$heldRsc[$thisTrade[11]] = 0; $heldRsc[$thisTrade[13]] = 0; $heldRsc[$thisTrade[15]] = 0; $heldRsc[$thisTrade[17]] = 0; $heldRsc[$thisTrade[19]] = 0; // Confirm that the purchasing player has the required resources $thisPlayer = loadPlayer($pGameID, $unitFile, 400); $thisHomeCity = loadUnit($thisPlayer->get('homeCity'), $unitFile, 400); $thisRsc = new itemSlot($thisHomeCity->get('carrySlot'), $slotFile, 40); for ($i = 1; $i < sizeof($thisRsc->slotData); $i += 2) { $heldRsc[$thisRsc->slotData[$i]] = $thisRsc->slotData[$i + 1]; } $rscCheck = true; for ($i = 11; $i < 20; $i += 2) { if ($heldRsc[$i] < $thisTrade[$i + 1]) { exit('Not enough resources'); } } // Confirm that the unit is not in an army $trgUnit = loadUnit($postVals[1], $unitFile, 400); if ($trgUnit->get('armyID') > 0) { exit('Can\'t sell a unit that is in an army'); } // Change the controller in the unit's information $trgUnit->save('controller', $pGameID); // Add the unit to the new controller's unit list $playerUnits = new itemSlot($thisPlayer->get('unitSlot'), $slotFile, 40); $playerUnits->addItem($postVals[1], $slotFile); fclose($slotFile); fclose($mercFile); fclose($unitFile);
echo 'Char slot for plot is ' . $plotDat[11] . '<br>'; $plotChars = new blockSlot($plotDat[11], $slotFile, 40); $loc = sizeof($plotChars->slotData); for ($i = 1; $i <= $plotChars->slotData; $i += 2) { if ($plotChars->slotData[$i] == 0) { $loc = $i; break; } } // Record plot in list of plaayer plots fseek($unitFile, $_SESSION['selectedItem'] * $defaultBlockSize); $unitDat = unpack('i*', fread($unitFile, 200)); //$plotChars->addItem($slotFile, pack('i*', $_SESSION['selectedItem'], 1), $loc); $plotChars->addItem($slotFile, pack('i*', $pGameID, 1), $loc); //echo 'Added character to plot at slot '.$plotDat[11]; fseek($unitFile, $unitDat[6] * $defaultBlockSize); $controllerDat = unpack('i*', fread($unitFile, 200)); echo 'Record plot in slot ' . $unitDat[35] . ' for the unit'; if ($controllerDat[20] == 0) { $controllerDat[20] = startASlot($slotFile, $gamePath . '/gameSlots.slt'); fseek($unitFile, $_SESSION['selectedItem'] * $defaultBlockSize + 136); fwrite($unitFile, pack('i', $controllerDat[20])); } $charPlots = new itemSlot($controllerDat[20], $slotFile, 40); $charPlots->addItem($postVals[1], $slotFile); // Send a message to the player that he has a char invited to a new plot $trgList[] = $unitDat[6]; sendMessage([$pGameId, $unitDat[6], time(), 1, 0, $postVals[1], $_SESSION['selectedItem']], "", $trgList); fclose($slotFile); fclose($unitFile); fclose($taskFile);
$slotFile = fopen($gamePath . '/gameSlots.slt', 'rb'); $credList = array_filter(unpack("i*", readSlotData($slotFile, $subCityDat[19], 40))); $approved = array_search($pGameID, $credList); echo 'Approved level ' . $approved . '<br>'; if ($approved) { if ($subCityDat[29] > 0) { fseek($unitFile, $subCityDat[29] * $defaultblocksize); $parCityDat = unpack('i*', fread($unitFile, 400)); // Remove from the list of child citys for the parent city $childCityList = new itemSlot($parCityDat[30], $slotFile); $target = array_search($_SESSION['selectedItem'], $childCityList->slotData); if ($target) { $childCityList->deleteItem($target, $slotFile); } } // Change the child city to a resource cart/moving group object /// Save location of the unit to match that of the city and adjust unit types fseek($unitFile, $_SESSION['selectedItem'] * $defaultblocksize); fwrite($unitFile, pack('i*', $parCityDat[1], $parCityDat[2], 10, 10, $pGameID, $pGameID, 1, 1, 1)); /// Update last change time fseek($unitFile, $_SESSION['selectedItem'] * $defaultblocksize + 104); fwrite($unitFile, pack('i', time())); /// Add to list of military units for this player fseek($unitFile, $pGameID * $defaultblocksize); $playerDat = unpack('i*', fread($unitFile, 400)); $unitList = new itemSlot($playerDat[22], $slotFile, 40); // start, file, size $unitList->addItem($_SESSION['selectedItem'], $slotFile); } fclose($slotFile); fclose($unitFile);
<?php include './slotFunctions.php'; include './unitClass.php'; echo 'Join battle ' . $postVals[1] . ' on side ' . $postVals[2]; $unitFile = fopen($gamePath . '/unitDat.dat', 'rb'); $slotFile = fopen($gamePath . '/gameSlots.slt', 'r+b'); $mapSlotFile = fopen($gamePath . '/mapSlotFile.slt', 'r+b'); $baseUnit = new warband($_SESSION['selectedUnit'], $unitFile, 400); $thisBattle = new battle($postVals[1], $unitFile, 100); // Verify that unit can join battle // Update unit status and save the battle ID to the unit $baseUnit->set('status', 2); $baseUnit->set('battleID', $postVals[1]); // Remove the unit from the map $mapSlotNum = floor($baseUnit->get('yLoc') / 120) * 120 + floor($baseUnit->get('xLoc') / 120); $mapSlotItem = new itemSlot($mapSlotNum, $mapSlotFile, 404); $location = array_search($_SESSION['selectedUnit'], $mapSlotItem->slotData); if ($location) { $mapSlotItem->deleteItem($location, $mapSlotFile); } // Add the unit to the battle list for the selected side $battleList = new itemSlot($thisBattle->get('sideList_1'), $slotFile, 40); $battleList->addItem($_SESSION['selectedUnit'], $slotFile); fclose($unitFile); fclose($slotFile); fclose($mapSlotFile);
<?php include './unitClass.php'; include "./slotFunctions.php"; include "./taskFunctions.php"; $unitFile = fopen($gamePath . '/unitDat.dat', 'r+b'); // Create a new plot task and save the parameters $taskFile = fopen($gamePath . '/tasks.tdt', 'r+b'); $taskIndex = fopen($gamePath . '/tasks.tix', 'r+b'); $parameters = pack('i*', 0, 0, 1, time(), 0, 0, 6, $_SESSION['selectedItem'], $pGameID, 2); $newTask = createTask($taskFile, $parameters); //createTask($taskFile, $taskIndex, $duration, $parameters, $gamePath, $slotFile) fclose($taskFile); fclose($taskIndex); // Add the new plot to the player's list of ongoing plots fseek($unitFile, $pGameID * $defaultBlockSize); $playerDat = unpack('i*', fread($unitFile, 200)); $slotFile = fopen($gamePath . '/gameSlots.slt', 'r+b'); if ($playerDat[20] == 0) { $newSlot = startASlot($slotFile, $gamePath . '/gameSlots.slt'); fseek($unitFile, $pGameID * $defaultBlockSize + 76); fwrite($unitFile, pack('i', $newSlot)); $playerDat[20] = $newSlot; } $plotSlot = new itemSlot($playerDat[20], $slotFile, 40); //$targetUnit = new unit($_SESSION['selectedUnit'], $unitFile); $plotSlot->addItem($newTask, $slotFile); fclose($slotFile); echo 'Record this task'; print_r($postVals); fclose($unitFile);
// Basic parameters fwrite($unitFile, pack("i*", $startLocation[0],$startLocation[1],1,$typeParams[3],$pGameID, $pGameID,1,$postVals[1],0)); // Secondary information fwrite($unitFile, pack("i*", $makeTypes[$i], 0, $townID)); fseek($unitFile, ($newId)*$defaultBlockSize+56); fwrite($unitFile, pack('i', $armyID)); */ //addDataToSlot($gamePath."/gameSlots.slt", $unitSlot, pack("N", $newId), $gameSlot); echo 'Record unit #' . $newId . ' in unit slot<br>'; $unitList->addItem($newId, $gameSlot); print_r($unitList->slotData); if (!$startTown) { echo 'Record in army slot<br>'; $armyObj->addItem($newId, $gameSlot); //->addItem($newId, $mapSlotFile); // value, file } else { //addDataToSlot($gamePath."/gameSlots.slt", $townUnitSlot, pack("i", $newId), $gameSlot); } } // If no town is being started, create a resource unit for the player if (!$startTown) { /* $newId = $unitIndex; $unitIndex +=4;; $thisDtl = explode('<-->', $unitInf[6]); $typeParams = explode(",", $thisDtl[1]); fseek($unitFile, ($newId)*$defaultBlockSize);
$outList[] = $postVals[$i]; } else { $inList[] = $postVals[$i]; } } // Review units being removed from the army - process all if player controls the army or only the ones that player controls. for ($i = 0; $i < sizeof($outList); $i++) { $outUnit = loadUnit($outList[$i], $unitFile, 400); if ($outUnit->get('controller') == $pGameID || $trgArmy->get('controller') == $pGameID) { echo 'Remove unit ' . $outList[$i]; // Process this unit out of the army $outUnit->save('armyID', 0); $armyUnits->deleteByValue($outList[$i], $slotFile); } } // Review units being added to the army - process all that the player controls if he also controls the army if ($trgArmy->get('controller') == $pGameID) { for ($i = 0; $i < sizeof($inList); $i++) { $inUnit = loadUnit($inList[$i], $unitFile, 400); if ($inUnit->get('controller') == $pGameID) { // Update unit to be in army $inUnit->save('armyID', $postVals[1]); // Add to army unit list $armyUnits->addItem($inList[$i], $slotFile); } } } else { echo 'Can\'t add to an army you don\'t control!'; } fclose($unitFile); fclose($slotFile);
$charSlot = new itemSlot($playerDat[19], $slotFile, 40); $charSlot->addItem($useBldg->unitDat[$postVals[2] + 18], $slotFile); break; case 6: // made a new warband // Record in player unit list echo 'Add to slot ' . $playerDat[22]; $unitList = new itemSlot($playerDat[22], $slotFile, 40); $unitList->addItem($useBldg->unitDat[$postVals[2] + 18], $slotFile); break; case 8: // made a new warband // Record in player unit list echo 'Add to slot ' . $playerDat[22]; $unitList = new itemSlot($playerDat[22], $slotFile, 40); $unitList->addItem($useBldg->unitDat[$postVals[2] + 18], $slotFile); break; } // Release building production slot $useBldg->unitDat[$postVals[2] + 18] = 0; // Add unit to map location slot $mapSlotNum = floor($trgUnit->unitDat[2] / 120) * 120 + floor($trgUnit->unitDat[1] / 120); $mapSlotFile = fopen($gamePath . '/mapSlotFile.slt', 'r+b'); if (flock($mapSlotFile, LOCK_EX)) { $mapSlot = new blockSlot($mapSlotNum, $mapSlotFile, 404); /// start, file, size $loc = sizeof($mapSlot->slotData); for ($m = 1; $m < sizeof($mapSlot->slotData); $m += 2) { if ($mapSlot->slotData[$m] == 0) { $loc = $m; break;
fclose($taskFile); echo '<p>Parameters:'; print_r(unpack('i*', $parameters)); // Record task in city task list // Verify that slot exists and create one if needed. if ($cityDat[21] == 0) { // Need to create a new slot echo 'Making a new slot'; $cityDat[21] = startASlot($slotFile, $gamePath . '/gameSlots.slt'); //startASlot($slot_file, $slot_handle) fseek($unitFile, $cityID * $defaultBlockSize + 80); fwrite($unitFile, pack('i', $cityDat[21])); } echo 'Record task (' . $newTask . ') in slot ' . $cityDat[21] . '<br>'; $taskSlot = new itemSlot($cityDat[21], $slotFile, 40); $taskSlot->addItem($newTask, $slotFile); //addDataToSlot($gamePath.'/gameSlots.slt', $cityDat[21], pack('i', $newTask), $slotFile); $checkSlot = new itemSlot($cityDat[21], $slotFile, 40); echo 'Result is:<p>'; print_r($checkSlot->slotData); // this is for adding to a map slot -> addtoSlotGen($gamePath.'/gameSlots.slt', $cityDat[21], pack('i', $taskIndex), $slot_file, 40) // function addtoSlotGen($slot_handle, $check_slot, $addData, $slot_file, $slotSize) } } else { if (sizeof($buildingsNeeded) > 0) { echo "Need more of the following buildings."; print_r($buildingsNeeded); } if (sizeof($neededRsc) > 0) { echo 'Need more of the following resoruces (City)'; print_r($neededRsc); }
fclose($pCharFile); // Save character with stats into game if (flock($unitFile, LOCK_EX)) { fseek($unitFile, 0, SEEK_END); $size = ftell($unitFile); $newID = $size / $defaultBlockSize; fseek($unitFile, $newID * $defaultBlockSize); fwrite($unitFile, $pUnitDat); flock($unitFile, LOCK_UN); } // Add game specific infomration /// Record locations, controller, etc fclose($unitFile); // Add character into player's list of available characters $unitList = new itemSlot($playerDat[19], $slotFile, 40); $unitList->addItem($newID, $slotFile); // Add to map if necessary /// Load map data $mapSlotFile = fopen($gamePath . '/mapSlotFile.slt', 'rb'); $mapSlotNum = floor($startLocation[1] / 120) * 120 + floor($startLocation[0] / 120); $mapSlotDat = new itemSlot($mapSlotNum, $mapSlotFile, 404); for ($i = 1; $i <= sizeof($mapSlotDat->slotData); $i++) { fseek($unitFile, $mapSlotDat->slotData[$i] * $defaultBlockSize); $mapCheckDat = unpack('i*', fread($unitFile, 400)); if ($mapCheckDat[1] == $newLoc[0] && $mapCheckDat[2] == $newLoc[1]) { switch ($mapCheckDat[4]) { /// Add to city if location is in city case 1: /// Add to army if location is in army` /// Add to army if location is in army` case 3:
$unitFile = fopen($gamePath . '/unitDat.dat', 'rb'); $slotFile = fopen($gamePath . '/gameSlots.slt', 'rb'); // Load unit infrmation $thisUnit = loadUnit($postVals[1], $unitFile, 400); // Load target unit information $trgUnit = loadUnit($postVals[2], $unitFile, 400); if ($trgUnit->get('uType') == 2) { // Add to an existing army // Record army id in unit information $thisUnit->save('armyID', $postVals[2]); // Record unit id in list of army units $unitList = new itemsSlot($trgUnit->get('unitListSlot'), $slotFile, 40); $unitList->addItem($postVals[1], $slotFile); } else { if ($trgUnit->get('uType') == 6) { // Combine with an existing unit to create a new army // Create a new army $newArmy = newUnit(2, $unitFile); // Create an item List for the army $newArmy->save('unitListSlot', newSlot($slotFile)); $armyUnits = new itemSlot($newArmy->get('unitListSlot')); // Record both unit IDs in the army unit list $armyUnits->addItem($postVals[1], $slotFile); $armyUnits->addItem($postVals[2], $slotFile); // Record army ID in both unit informations $thisUnit->save('armyID', $newArmy->get('unitListSlot')); $trgUnit->save('armyID', $newArmy->get('unitListSlot')); } } fclose($unitFile); fclose($slotFile);
// Add the parent city ID to the current city fseek($unitFile, $_SESSION['selectedItem'] * $defaultBlockSize + 112); fwrite($unitFile, pack('i', $newCityId)); // Remove the unit cart / other items from the map and change the mapslot to display the new city $mapSlotFile = fopen($gamePath . '/mapSlotFile.slt', 'r+b'); $mapSlotNum = floor($unitDat[2] / 120) * 120 + floor($unitDat[1] / 120); echo 'Mapo slot number is ' . $mapSlotNum . '<br>'; $mapSlot = new itemSlot($mapSlotNum, $mapSlotFile, 404); print_r($mapSlot->slotData); $currentPos = array_search($_SESSION['selectedItem'], $mapSlot->slotData); echo 'Current Pos: ' . $currentPos . '<br>'; if ($currentPos) { $mapSlot->deleteItem($currentPos, $mapSlotFile); } echo 'Add new city to map item List<br>'; $mapSlot->addItem($newCityId, $mapSlotFile); // Add this player to the credential list for the city echo 'Open city ' . $newCityId . '<br>'; $thisCity = new city($newCityId, $unitFile); $cityCredentials = new blockSlot($thisCity->cityData[19], $slotFile, 40); $addLoc = array_search(0, $cityCredentials->slotData); echo 'Add credintials to slot (' . $thisCity->cityData[19] . ')'; print_r($cityCredentials->slotData); $cityCredentials->addItem($slotFile, pack('i*', -9, $pGameID), $addLoc); // Change this cart object to a city object fseek($unitFile, $_SESSION['selectedItem'] * $defaultBlockSize + 12); fwrite($unitFile, pack('i', 1)); // Remove the cart from the list of military units the player controls $playerObj = new player($pGameID, $unitFile, 400); $unitList = new itemSlot($playerObj->get('unitSlot'), $slotFile, 40); $unitList->deleteByValue($_SESSION['selectedItem'], $slotFile);