Esempio n. 1
0
function TB_run_flowermanager($getFarm = null)
{
    global $TB_settings;
    global $AM_settings;
    //########################################################################
    // flowermanager functions
    //########################################################################
    AddLog2("FlowerManager");
    $farm = $getFarm;
    $cdf = count(FM_getDroop());
    if ($TB_settings['FM_action'] != 'nothing' && $cdf > 0) {
        AddLog2('FlowerManager: ' . $cdf . ' droopy flowers');
        switch ($TB_settings['FM_action']) {
            case 'delet':
                FM_delet();
                break;
            case 'replace':
                FM_replace();
                break;
        }
        $TB_settings['TB_needReload'] = true;
    }
    if (isset($TB_settings['FM_actionP']['place'])) {
        if (count($TB_settings['FM_actionP']['place']) > 0) {
            if (!isset($farm)) {
                AddLog2('TB - reloding farm');
                DoInit();
                $farm = TB_buildFarmArray();
            }
            $re = FM_place($farm);
            if (is_array($re)) {
                $farm = $re;
            }
        }
        $TB_settings['TB_needReload'] = true;
    }
    return $farm;
}
Esempio n. 2
0
function FM_replace()
{
    global $TB_settings;
    $flowers = array();
    $flowers = FM_getDroop();
    switch ($TB_settings['FM_replaceSource']) {
        case 'shed':
            $shed = FM_loadFlowershed();
            if ($shed == 0) {
                AddLog2('no shed');
                return false;
            } elseif (count($shed['contents']) == 0) {
                AddLog2('no flowers in shed');
            }
            foreach ($flowers as $dFlower) {
                $found = false;
                AddLog2("try to replace " . GetNameByItem($dFlower['itemName']));
                foreach ($shed['contents'] as $key => $sFlower) {
                    if (GetNameByCode($sFlower['itemCode']) == $dFlower['itemName'] || !$TB_settings['FM_replaceSame']) {
                        if ($sFlower['numItem'] > 0) {
                            AddLog2("Replacing " . GetNameByItem($dFlower['itemName']) . " with " . GetNameByItem($sFlower['itemCode']));
                            if (FM_doShed($dFlower, $shed, GetNameByCode($sFlower['itemCode']))) {
                                $sFlower['numItem']--;
                                $shed['contents'][$key]['numItem']--;
                                $found = true;
                            } else {
                                return false;
                            }
                        }
                    }
                    if ($found) {
                        break;
                    }
                }
                if (!$found) {
                    AddLog2('no flower in shed or gift box');
                } else {
                    AddLog2('done!');
                }
            }
            break;
        case 'giftbox':
            $giftbox = FM_getGiftbox();
            if (count($giftbox) == 0) {
                AddLog2('giftbox is empty');
                return false;
            }
            foreach ($flowers as $dFlower) {
                $found = false;
                AddLog2("try to replace " . GetNameByItem($dFlower['itemName']));
                foreach ($giftbox as $gFlower => $num) {
                    if ($gFlower == $dFlower['itemName'] || !$TB_settings['FM_replaceSame']) {
                        if ($num > 0) {
                            AddLog2("Replacing " . GetNameByItem($dFlower['itemName']) . " with " . GetNameByItem($gFlower));
                            if (FM_doGiftBox($dFlower, $gFlower)) {
                                $giftbox[$gFlower]--;
                                $found = true;
                            } else {
                                return false;
                            }
                        }
                    }
                    if ($found) {
                        break;
                    }
                }
                if (!$found) {
                    AddLog2('no flower in shed or gift box');
                } else {
                    AddLog2('done!');
                }
            }
            break;
        case 'both':
            $shed = FM_loadFlowershed();
            $giftbox = FM_getGiftbox();
            if ($shed == 0) {
                AddLog2('no shed');
            } elseif (count($shed['contents']) == 0) {
                AddLog2('no flowers in shed');
            }
            if (count($giftbox) == 0) {
                AddLog2('giftbox is empty');
            }
            foreach ($flowers as $dFlower) {
                $found = false;
                AddLog2("try to replace " . GetNameByItem($dFlower['itemName']));
                if (count($shed['contents']) > 0) {
                    foreach ($shed['contents'] as $key => $sFlower) {
                        if (GetNameByCode($sFlower['itemCode']) == $dFlower['itemName'] || !$TB_settings['FM_replaceSame']) {
                            if ($sFlower['numItem'] > 0) {
                                AddLog2("Replacing " . GetNameByItem($dFlower['itemName']) . " with " . GetNameByItem($sFlower['itemCode']));
                                if (FM_doShed($dFlower, $shed, GetNameByCode($sFlower['itemCode']))) {
                                    $sFlower['numItem']--;
                                    $shed['contents'][$key]['numItem']--;
                                    $found = true;
                                } else {
                                    return false;
                                }
                            }
                        }
                        if ($found) {
                            break;
                        }
                    }
                }
                if (!$found && count($giftbox) > 0) {
                    foreach ($giftbox as $gFlower => $num) {
                        if ($gFlower == $dFlower['itemName'] || !$TB_settings['FM_replaceSame']) {
                            if ($num > 0) {
                                AddLog2("Replacing " . GetNameByItem($dFlower['itemName']) . " with " . GetNameByItem($gFlower));
                                if (FM_doGiftBox($dFlower, $gFlower)) {
                                    $giftbox[$gFlower]--;
                                    $found = true;
                                } else {
                                    return false;
                                }
                            }
                        }
                        if ($found) {
                            break;
                        }
                    }
                }
                if (!$found) {
                    AddLog2('no flower in shed or gift box');
                } else {
                    AddLog2('done!');
                }
            }
            break;
    }
    return true;
}