echo GB_TabTable2($FromName); echo "<br>"; echo "<br>"; } // *************************************************************************** // *** Menu Screen $GB_current_url = "collection"; // *** // *************************************************************************** if ($GB_url == $GB_current_url) { echo '<h2>Collection</h2><p>'; echo '<b>Collection information:</b><br> Note that this information only updates at the begin of a cycle. So it is alway 1 cycle behind.'; echo '<br>'; echo '<table class="sofT" cellspacing="0">'; echo "<tr>"; $GBccount = GB_LoadCcount(); $GB_CollectionList = GB_GetCollectionList(); if (!$GB_CollectionList) { echo $GB_file_error . "<br><br>(Collection list file missing)"; return; } foreach ($GB_CollectionList as $value) { echo '<td class="helpLeft">' . $value['name'] . "</td>"; $GB_amount_Coll = count($value['collectable']); $i = 0; while ($i < $GB_amount_Coll) { $unit = Units_GetUnitByCode($value['collectable'][$i]); $Amount_in_Collection = GB_GetColInfo($value['collectable'][$i], $GBccount); $BG_color = " class=\"lime\""; if ($Amount_in_Collection == "10") { $BG_color = " class=\"lgreen\"";
function Giftbox() { AddLog2('GiftBox: Start'); $T = time(true); // begin SQL setup $this->GBDBuser_init("Hook"); $this->GB_renew_giftbox_SQL(); // end SQL setup // Get the settings $GBSQL = "SELECT _val,_set FROM gamesettings"; $result = $this->_GBUser->query($GBSQL); if ($result->numRows() > 0) { $GB_results = $result->fetchAll(); foreach ($GB_results as $GB_result) { $this->GB_Setting[$GB_result['_set']] = $GB_result['_val']; } } // import default actions? $this->GB_AutoActionFile(); // if place is on, than let's update the locations to find empty locations if ($this->GB_Setting['DoPlace']) { $this->GBCreateMap(); } AddLog2('GiftBox: Detecting Building Parts'); $this->GB_DetectBuildingParts4(); $this->GB_BuildingParts4(); if ($this->GB_Setting['RunPlugin']) { //check the cellar for storage. if ($this->GB_Setting['DoStorage']) { $this->GB_checkCellar(); } // check this amount of items in giftbox. $result1 = $this->_GBUser->query("SELECT SUM(_amount) FROM giftbox"); if ($result1->numRows() > 0) { $GB_total_in_giftbox = $result1->fetchSingle(); } else { $GB_total_in_giftbox = 0; } AddLog2("GiftBox: Items Counted - " . $GB_total_in_giftbox); global $GB_tempid; if ($GB_tempid == "") { $GB_tempid = 63000; } //get the collection info. $GBccount = array(); $GBccount = GB_LoadCcount(); $GB_changed = false; //true when we did action. $MAP_ObjectArray = array(); $Map_all_items = array(); $MapXY = array(); $EmptyXY = array(); if ($this->GB_Setting['DoFeetPet']) { AddLog2("GiftBox: Detecting Pet(s)"); $GB_Pets = $this->GB_FindPetsSQL(); $found = count(array_keys($GB_Pets)); AddLog2("GiftBox: Found {$found} Pet(s)"); if ($found > 0) { foreach ($GB_Pets as $GB_Petfeed) { if ($GB_Petfeed['isRunAway'] == 1) { AddLog2('GiftBox: ' . $GB_Petfeed['petName'] . ' Has Ran Away'); } else { $FeedWhat = $GB_Petfeed['FeedWhat']; $FeedName = $GB_Petfeed['petName']; AddLog2('GiftBox: ' . $FeedName . ' Needs: ' . $FeedWhat . ' ' . nicetime($GB_Petfeed['feedtime'])); } } } } // DoFeetPet // load the totstorage. $GBSQL = "SELECT * FROM totstorage "; $query = $this->_GBUser->query($GBSQL); $totstorages = $query->fetchAll(); if (!is_array($totstorages)) { $totstorages = array(); } // load the giftbox... $GBSQL = "SELECT * FROM giftbox "; $query = $this->_GBUser->query($GBSQL); $giftboxs = $query->fetchAll(); foreach ($giftboxs as $giftbox) { $GB_ItemCode = $giftbox["_itemcode"]; $GB_ItemAmount = $giftbox["_amount"]; // if items = 0 then skip this item. if ($GB_ItemAmount < 1) { continue; } $place_on_farm = ''; $place_in_build = ''; $place_in_amount = ''; $place_in_max = ''; $place_in_special = ''; $target = ''; $selling = ''; $keep = 0; $construction = ''; $collection = ''; $consume = ''; // Let's check if there is action for this item. $GBSQL = "SELECT * FROM action WHERE _code = '" . $GB_ItemCode . "'"; $query = $this->_GBUser->query($GBSQL); $action = $query->fetchAll(); if (!empty($action)) { // so there is action. $place_on_farm = $action['0']['_place_on_farm']; $place_in_build = $action['0']['_place_in_build']; $place_in_amount = $action['0']['_place_in_amount']; $place_in_max = $action['0']['_place_in_max']; $place_in_special = $action['0']['_place_in_special']; $target = $action['0']['_target']; $selling = $action['0']['_selling']; $construction = $action['0']['_construction']; $keep = $action['0']['_keep']; $collection = $action['0']['_collection']; $consume = $action['0']['_consume']; } // prepare Unit settings $GBSQL = "SELECT * FROM units WHERE _code = '" . $GB_ItemCode . "' "; $query = $this->_GBMain->query($GBSQL); $Unit = $query->fetchAll(); // Get the realname $Unit['0']['realname'] = $this->GB_get_friendlyName($Unit['0']['_name']); // check if we need to feed pet $FeedNowCheck = false; $PetFeedFound = ""; if ($GB_ItemCode == "0O") { $FeedNowCheck = true; $PetFeedFound = "Puppy Kibble "; } if ($GB_ItemCode == "0z") { $FeedNowCheck = true; $PetFeedFound = "Dog Treat "; } if ($FeedNowCheck == true && $this->GB_Setting['DoFeetPet']) { AddLog('GiftBox: ' . $GB_ItemAmount . " " . $PetFeedFound . " Found - Checking If Needed"); if ($GB_ItemAmount > 0) { // loop all pets foreach ($GB_Pets as $GB_Petfeed) { if ($GB_Petfeed['isRunAway'] == 1) { AddLog2('GiftBox: ' . $GB_Petfeed['petName'] . ' Has Ran Away - Cannot Feed'); } else { $FeedWhat = $GB_Petfeed['FeedWhat']; $FeedName = $GB_Petfeed['petName']; $FeedNow = true; if ($FeedWhat == "kibble" && $GB_ItemCode == "0z") { AddLog2("GiftBox: This Puppy Does Not Need Dog Treats.."); $FeedNow = false; } if ($FeedWhat == "treat" && $GB_ItemCode == "0O") { AddLog2("GiftBox: This Dog Does Not Need Kibble.."); $FeedNow = false; } if ($FeedNow == true) { $UnixNow = time(); if ($UnixNow > $GB_Petfeed['feedtime']) { // need feed now $FeedWhat = $GB_Petfeed['FeedWhat']; $result = GB_consumePet($GB_Petfeed['id'], "consume_" . $FeedWhat); AddLog2("GiftBox: Feeding " . $GB_Petfeed['petName'] . " " . $FeedWhat . '- ' . $result); if ($result == "OK") { AddLog2("GiftBox: Kibble Has Been Fed"); $GB_changed = true; // giftbox changed $this->GB_Stat3($GB_ItemCode, "Pet feed", $GB_ItemAmount, "Pet Feed"); //GB_Stat($GB_ItemCode, "Kibble feed", 0, 0, $GB_ItemAmount,0 ); } else { $giftboxs = array(); break; } } else { AddLog2($GB_Petfeed['petName'] . ' Needs to be Fed ' . nicetime($GB_Petfeed['feedtime'])); } } } } } } // End pet feet. // check target settings global. if ($target != 0) { $Target = $this->GBSQLGetObjByID($target); $TotItems = 0; $TargetItemHave = 0; // map the content of the target and find the total items have if (is_array($Target['contents'])) { // count the contents foreach ($Target['contents'] as $content) { $TotItems = $TotItems + $content['numItem']; $TargetCont[$content['itemCode']] = $content['numItem']; if ($GB_ItemCode == $content['itemCode']) { $TargetItemHave = $content['numItem']; } } } // end contents // now check if the item is in totstorage. $featureCreditsName = 'N'; if ($Target['itemName'] == 'valentinesbox') { $featureCreditsName = 'valentine'; } if ($Target['itemName'] == 'potofgold') { $featureCreditsName = 'potOfGold'; } if ($Target['itemName'] == 'easterbasket') { $featureCreditsName = 'easterBasket'; } if ($Target['itemName'] == 'wedding') { $featureCreditsName = 'tuscanWedding'; } if ($Target['itemName'] == 'beehive_finished') { $featureCreditsName = 'beehive'; } if ($Target['itemName'] == 'hatchstorage') { $featureCreditsName = 'InventoryCellar'; } //added if ($featureCreditsName != 'N') { $GBSQL = "SELECT * FROM totstorage WHERE _storagecode = '" . $featureCreditsName . "' AND _itemcode = 'current'"; $query = $this->_GBUser->query($GBSQL); if ($query->numRows() > 0) { $totstorage = $query->fetchAll(); $TotItems = $totstorages['0']['_amount']; } } // Get target unit details. $GBSQL = "SELECT * FROM units WHERE _name = '" . $Target['itemName'] . "' "; $result = $this->_GBMain->query($GBSQL); $TargetUnit = $result->fetchAll(); // check capacity of target $TargetCapacity = 0; if (!array_key_exists('isFullyBuilt', $Target)) { $Target['isFullyBuilt'] = "N"; } if ($Target['isFullyBuilt'] == "1") { $TargetCapacity = $TargetUnit['0']['_capacity']; if (array_key_exists('expansionLevel', $Target)) { $level = $Target['expansionLevel']; if ($level > 1) { $GBSQL = "SELECT _capacity FROM unitbuilding WHERE _level = '" . $level . "' AND _buildingcode = '" . $TargetUnit['0']['_code'] . "' "; $result = $this->_GBMain->query($GBSQL); $TargetCapacity = $result->fetchSingle(); } } else { $level = 0; } } // end fully build // check if building is in construction $TargetIsConstruction = 'N'; if ($Target['state'] == 'construction') { $TargetIsConstruction = 'Y'; } else { // check if it is a horsestable if ($Target['itemName'] == 'horsestablewhite') { // check if horse stable has expansionParts if (count(array_keys($Target['expansionParts'])) > 0) { // yes, we have expansionParts $TargetIsConstruction = 'Y'; } if ($TargetItemHave > 0) { // yes, we have expansionParts $TargetIsConstruction = 'Y'; } } } } // End check target //check if we can store this item. if ($this->GB_Setting['DoStorage']) { $Able2Store = GB_CanWeStore($Unit['0']); if ($this->GB_Setting['StorageLocation'] == 'N') { $Able2Store = 'N'; } else { if ($this->GB_Setting['StorageUsed'] >= $this->GB_Setting['StorageCapacity']) { // storage is full. $Able2Store = 'N'; AddLog2("GiftBox: Storage is Full?"); } } if ($this->GB_Setting['DoStorage'] && $Able2Store == 'Y' && $GB_ItemAmount > 0) { // check content of storage AddLog2("GiftBox: Entering Storage Routine For: " . $Unit['0']['realname']); $cellars = unserialize($this->GB_Setting['StorageContent2']); $AmountInCellar = 0; if (array_key_exists($GB_ItemCode, $cellars)) { $AmountInCellar = $cellars[$GB_ItemCode]; } AddLog2("GiftBox: Store " . $GB_ItemAmount . " " . $Unit['0']['realname'] . '?'); if ($this->GB_Setting['DoStorage1'] && $AmountInCellar < 1) { $Amount2Store = 1; AddLog2("GiftBox: Store " . $Amount2Store . " " . $Unit['0']['realname']); } else { AddLog2("GiftBox: Store " . $Unit['0']['realname'] . " Already in Storage"); } if ($Amount2Store > 0) { $result = GB_StoreCel($Unit['0'], $Amount2Store); if ($result == "OK") { AddLog2("GiftBox: " . $GB_ItemAmount . " " . $Unit['0']['realname'] . " - Added"); $GB_changed = true; // giftbox changed $this->GB_Stat3($GB_ItemCode, $Unit['0']['_name'], $GB_ItemAmount, "Fuel added"); $GB_ItemAmount = $GB_ItemAmount - $Amount2Store; } else { $giftboxs = array(); break; } } else { AddLog2("GiftBox: No Need to Store This Item."); } } // end stor } // check if we can use the item to store into a building if ($place_in_build != 0 && $target != 0 && $this->GB_Setting['DoPlaceBuild'] && $GB_ItemAmount > 0) { //$place_in_max AddLog2('GiftBox ' . $Target['itemName'] . ' - Capacity: ' . $TargetCapacity . ' - Have: ' . $TotItems); $finished = false; if ($TotItems >= $TargetCapacity) { // The building is full lets skip this item. AddLog2("GiftBox: This Building is Full - Skipping"); $finished = true; } while (!$finished) { $result = GB_storeItem($Unit['0'], $Target); if ($result == "OK") { $GB_changed = true; //update the amount. AddLog2('GiftBox: Placed in Building ' . $Unit['0']['_name'] . ' - Total in Building: ' . $TotItems); $this->GB_SQL_updAction("_place_in_build", $GB_ItemCode, $place_in_build - $GB_ItemAmount); //$field, $code, $val //update stats. $this->GB_Stat3($GB_ItemCode, $Unit['0']['_name'], $GB_ItemAmount, "Into building"); $TotItems++; $GB_ItemAmount--; } else { $finished = true; $giftboxs = array(); break; } if ($TotItems >= $TargetCapacity) { $finished = true; } if ($GB_ItemAmount < 1) { $finished = true; } } // not full } //end place in build // check if we have to place construction in a building // construction = # or Y 0 = not construction if ($construction == 'Y' && $this->GB_Setting['DoConstr'] && $GB_ItemAmount > 0) { $go = $GB_ItemAmount; $used = 0; while ($go > 0) { AddLog2('GiftBox: Construction Part ' . $Unit['0']['_name'] . ' Found ' . $go); $GBSQL = "SELECT * FROM BuildingParts WHERE _itemCode = " . $this->Qs($GB_ItemCode) . " AND _action ='construction' AND _ObjHave < 10 LIMIT " . $go; $query = $this->_GBUser->query($GBSQL); if ($query->numRows() > 0) { $BuildingParts = $query->fetchAll(); foreach ($BuildingParts as $BuildingPart) { // 1 or more targets found $Target = $this->GBSQLGetObjByID($BuildingPart['_ObjId']); AddLog2('GiftBox: Part: ' . $BuildingPart['_itemName'] . ' For ' . $BuildingPart['_UnitBuildName'] . " - Contains: " . $BuildingPart['_ObjHave'] . " - Adding 1"); $result = GB_storeItem($Unit['0'], $Target); if ($result == "OK") { $GB_changed = true; $this->GB_Stat3($GB_ItemCode, $Unit['0']['_name'], $GB_ItemAmount, "Construction"); //update the amount have $have = $BuildingPart['_ObjHave'] + 1; $GBSQL = "UPDATE BuildingParts SET _ObjHave=" . $this->Qs($have) . " WHERE _UnitBuildName = " . $this->Qs($BuildingPart['_UnitBuildName']) . " AND _itemCode = " . $this->Qs($GB_ItemCode); $query = $this->_GBUser->query($GBSQL); $go--; $used++; } else { $go = 0; $giftboxs = array(); break; } } } else { //skip there are no target buildings AddLog2('GiftBox: Construction Part Not Needed. (' . $GB_ItemCode . ')'); $go = 0; } } // while $GB_ItemAmount > 1 $GB_ItemAmount = $GB_ItemAmount - $used; } // constructions // check if we have Special to handle if ($place_in_special != 0 && $target != 0 && $this->GB_Setting['DoSpecials'] && $GB_ItemAmount > 0) { AddLog2('GiftBox: Special ' . $TargetUnit['0']['_name'] . " For " . $Target['itemName']); // for specials there is no max. $result = GB_storeItem2($Unit['0'], $Target, $GB_ItemAmount); if ($result == "OK") { //GB_SpecialThisUpdate($GB_ItemCode, $GB_ItemAmount); $GB_changed = true; $this->GB_Stat3($GB_ItemCode, $Unit['0']['_name'], $GB_ItemAmount, "Special"); $GB_ItemAmount = 0; } else { $giftboxs = array(); break; } } // check if we have collection if ($collection == 'Y' && $this->GB_Setting['DoColl'] && $GB_ItemAmount > 0) { $Amount_in_Collection = GB_GetColInfo($GB_ItemCode, $GBccount); // Check if we have less than 10 if ($Amount_in_Collection < 10 && $GB_ItemAmount > 0) { if ($Amount_in_Collection + $GB_ItemAmount <= 10) { $Amount_to_add = $GB_ItemAmount; } else { $Amount_to_add = 10 - $Amount_in_Collection; } AddLog2("GiftBox: " . $GB_ItemAmount . " " . $Unit['0']['_name'] . " - Have " . $Amount_in_Collection . " Will Add " . $Amount_to_add . " To Collection"); $result = GB_DoColAdd($Unit['0']['_name'], $GB_ItemCode, $Amount_to_add); if ($result == "OK") { AddLog2($Amount_to_add . " " . $Unit['0']['_name'] . " Added To Collection"); $GB_changed = true; $this->GB_Stat3($GB_ItemCode, $Unit['0']['_name'], $GB_ItemAmount, "Added collection"); $Amount_in_Collection = $Amount_in_Collection + $Amount_to_add; $GB_ItemAmount = $GB_ItemAmount - $Amount_to_add; } else { $giftboxs = array(); break; } } // end < 10 if ($Amount_in_Collection >= 10 && $GB_ItemAmount > 0) { //we have already 10 if ($this->GB_Setting['DoCollSell']) { AddLog2("GiftBox: " . $GB_ItemAmount . " " . $Unit['0']['_name'] . " - Have " . $Amount_in_Collection . " Will Sell Now"); $result = GB_DoSellCol($Unit['0'], $GB_ItemAmount); if ($result == "OK") { AddLog2("GiftBox: " . $GB_ItemAmount . " " . $Unit['0']['realname'] . " Sold"); $GB_changed = true; $this->GB_Stat3($GB_ItemCode, $Unit['0']['_name'], $GB_ItemAmount, "Sold collection"); } else { $giftboxs = array(); break; } } else { AddLog2("GiftBox: " . $GB_ItemAmount . " " . $ObjD['realname'] . " - Have " . $Amount_in_Collection . " Selling Disabled"); } // end do_sell } // end more 10. } // end collection // Place on farm if ($place_on_farm == 'Y' && $this->GB_Setting['DoPlace'] && $GB_ItemAmount > 0) { AddLog2("GiftBox: " . $GB_ItemAmount . " " . $Unit['0']['realname'] . " - Place on Farm"); $GB_Where = "Decoration"; if ($Unit['0']['_type'] == "animal") { $GB_Where = "Animal"; } if ($Unit['0']['_type'] == "tree") { $GB_Where = "Tree"; } //check if there is place on the farm. $GB_Free_place = $this->TEmptyXY3($GB_Where, "ALL"); if ($GB_Free_place < $GB_ItemAmount) { AddLog2("****** Error *****"); AddLog2("GiftBox: There is no room on you farm left."); AddLog2("GiftBox: To place: " . $GB_ItemAmount . " " . $Unit['0']['realname']); AddLog2("****** Error *****"); } else { $result = GB_PlaceM3($Unit['0'], $GB_ItemAmount, $GB_Where); if ($result == "OK") { AddLog2("GiftBox: " . $GB_ItemAmount . " " . $Unit['0']['realname'] . " Placed"); $GB_changed = true; // giftbox changed $this->GB_Stat3($GB_ItemCode, $Unit['0']['_name'], $GB_ItemAmount, "Placed"); $GB_ItemAmount = 0; } else { $giftboxs = array(); break; } } } // end place if ($Unit['0']['_type'] == 'fuel' && $this->GB_Setting['DoFuel'] && $GB_ItemAmount > 0) { // selling fuel enabled >> GB_BuyFuel($ObjD , $GB_amount) $result = GB_BuyFuel($Unit['0'], $GB_ItemAmount); AddLog2("GiftBox " . $GB_ItemAmount . " " . $Unit['0']['realname'] . " Fuel found - " . $result); if ($result == "OK") { AddLog2("GiftBox " . $GB_ItemAmount . " " . $Unit['0']['realname'] . " Added"); $GB_changed = true; // giftbox changed $this->GB_Stat3($GB_ItemCode, $Unit['0']['_name'], $GB_ItemAmount, "Fuel added"); $GB_ItemAmount = 0; } else { $giftboxs = array(); break; } } // end fuel // consumable if ($consume == 'Y' && $GB_ItemAmount > 0) { $GBAction_Amount = $GB_ItemAmount - $keep; if ($GBAction_Amount >= 1) { $result = GB_consume($Unit['0'], $GBAction_Amount); AddLog2("GiftBox: " . $GB_ItemAmount . " " . $Unit['0']['realname'] . " Consume - Leave in GiftBox: " . $keep . ' - ' . $result); $need_reload = true; if ($result == "OK") { AddLog2("GiftBox: " . $GBAction_Amount . " " . $Unit['0']['realname'] . " Consumed"); $GB_changed = true; // giftbox changed $this->GB_Stat3($GB_ItemCode, $Unit['0']['_name'], $GBAction_Amount, "Consume"); $GB_ItemAmount = 0; } else { DoInit(); $giftboxs = array(); break; } } else { AddLog2("GiftBox: " . $GB_ItemAmount . " " . $Unit['0']['realname'] . " - Keep in Giftbox: " . $keep); } } // end consumable // DoVehicle if ($this->GB_Setting['DoVehicle'] && $GB_ItemCode == "dS" && $GB_ItemAmount > 0) { $GBAction_Amount = $GB_ItemAmount - $keep; $vehicle = $this->GB_garage('hook'); $AmountOfRuns = $vehicle['0']['vehicle']; AddLog2("GiftBox: Have " . $GB_ItemAmount . " Vehicle Parts - " . $vehicle['0']['vehicle'] . " Vehicles Need Parts"); while ($AmountOfRuns >= 1 && $GBAction_Amount > 1) { $needpart = $vehicle[$AmountOfRuns]['need']; AddLog2("Giftbox: Vehicle " . $vehicle[$AmountOfRuns]['itemCode'] . " Needs " . $needpart . " Parts"); while ($needpart >= 1 && $GBAction_Amount > 1) { $result = GB_DoGarage($vehicle[$AmountOfRuns], $vehicle['0']['id']); if ($result == "OK") { $vehicle[$AmountOfRuns]['numParts'] = $vehicle[$AmountOfRuns]['numParts'] + 1; $needpart--; AddLog2("GiftBox: 1 " . $Unit['0']['realname'] . " Added, Need " . $needpart . ' More'); $GB_changed = true; // giftbox changed $this->GB_Stat3($GB_ItemCode, $Unit['0']['_name'], $GBAction_Amount, "Added"); $GBAction_Amount--; $GB_ItemAmount--; } else { $giftboxs = array(); break; } } $AmountOfRuns--; } } // end DoVehicle // check if we can open this. $GB_OpenArray = unserialize($this->GB_Setting['OpenItems']); if (in_array($GB_ItemCode, $GB_OpenArray)) { $GB_OpenThis = 'Y'; } else { $GB_OpenThis = 'N'; } if ($this->GB_Setting['DoMystery'] && $GB_ItemAmount > 0 && $GB_OpenThis == 'Y') { $GBAction_Amount = $GB_ItemAmount - $keep; if ($GBAction_Amount >= 1) { $result = GB_OpenGift($Unit['0'], $GBAction_Amount); AddLog2("GiftBox: Open " . $GB_ItemAmount . " " . $Unit['0']['realname'] . " - " . $result); $need_reload = true; if ($result == "OK") { AddLog2("GiftBox: Opened " . $GBAction_Amount . " " . $Unit['0']['realname'] . " - Done"); $GB_changed = true; // giftbox changed $this->GB_Stat3($GB_ItemCode, $Unit['0']['_name'], $GBAction_Amount, "Opened"); $GB_ItemAmount = 0; } else { $giftboxs = array(); break; } } else { AddLog2("GiftBox: " . $GB_ItemAmount . " " . $Unit['0']['realname'] . " - Keep in GiftBox: " . $keep); } } // end open if ($selling == 'Y' && $this->GB_Setting['DoSelling'] && $GB_ItemAmount > 0) { $GBAction_Amount = $GB_ItemAmount - $keep; if ($GBAction_Amount >= 1) { $result = GB_DoSellCol($Unit['0'], $GBAction_Amount); AddLog2("GiftBox: " . $GB_ItemAmount . " " . $Unit['0']['realname'] . " Will be Sold - Leave in GiftBox: " . $keep . ' - ' . $result); $need_reload = true; if ($result == "OK") { AddLog2("GiftBox: " . $GBAction_Amount . " " . $Unit['0']['realname'] . " Sold"); $GB_changed = true; // giftbox changed $this->GB_Stat3($GB_ItemCode, $Unit['0']['_name'], $GBAction_Amount, "Sold"); $GB_ItemAmount = 0; } else { $giftboxs = array(); break; } } else { AddLog2("GiftBox: " . $GB_ItemAmount . " " . $Unit['0']['realname'] . " - Keep in GiftBox: " . $keep); } } // end Do_SellList } //end foreach giftbox // after giftbox, see the collection trade in. if ($this->GB_Setting['DoCollTrade']) { // now look to complete collections. AddLog2("Collection trade in set to: " . $this->GB_Setting['DoCollKeep']); $GB_CollCompete_res = GB_CollCompete(); // get the information while (list($GB_CollCode, $amount) = each($GB_CollCompete_res)) { AddLog2("Collection Info: [" . $GB_CollCode . "] has" . $amount . " completed"); $GB_Tradein_amount = $amount - $this->GB_Setting['DoCollKeep']; if ($GB_Tradein_amount > 0) { $GB_TradeIn_res = GB_TradeIn($GB_CollCode, $GB_Tradein_amount); AddLog2("Collection Trade In: [" . $GB_CollCode . "] " . $GB_Tradein_amount . " Time(s)"); $this->GB_Stat3($GB_CollCode, "Collection", $GB_Tradein_amount, "Trade in"); $GB_changed = true; } } } // end complete collection } else { AddLog2("Skipping GiftBox..."); } if ($GB_changed) { $res = $this->GB_renew_giftbox_SQL(); // update giftbox. so it shows correctly in the screen. } else { $T2 = time(); $T2 -= $T; AddLog2("Giftbox: Finished in " . $T2 . " Seconds"); } }
function GB_CollAmount() { $GB_CollectionList = GB_GetCollectionList(); if (!$GB_CollectionList) { return false; } $GB_CollCompl = 0; $GBccount = array(); $GBccount = GB_LoadCcount(); if (!$GBccount) { return false; } foreach ($GB_CollectionList as $value) { // walk all collections $GB_amount_Coll = count($value['collectable']); $i = 0; $GB_ThisCollCompl = 0; $GB_ThisCollVal = array(); while ($i < $GB_amount_Coll) { // each collection $Amount_in_Collection = GB_GetColInfo($value['collectable'][$i], $GBccount); $GB_ThisCollVal[] = $Amount_in_Collection; $i++; } $GB_ThisCollCompl = min($GB_ThisCollVal); $GB_CollCompl = $GB_CollCompl + $GB_ThisCollCompl; } return $GB_CollCompl; //return total completed }