public BuyUnitCommand(UnitType unitType, PlayerType playerType) { this.playerType = playerType; this.unitType = unitType; model = null; Debug.Log("buy unit command created"); }
public UnitTrainer(PlayerType playerType) { this.playerType = playerType; isTraining = false; currentTick = 0; requiredTicks = 0; model = null; }
private void SetPurchaseInfo() { UnitPurchaseModel model = UnitPurchaseModelFactory.Create(type); string wood = model.buildCost.TransactionStatusString(ResourceType.WOOD); string magicStone = model.buildCost.TransactionStatusString(ResourceType.MAGIC_STONE); string buildTime = (model.trainingTime / 5).ToString() + "s"; purchaseInfo.text = string.Format("Supply: {0}\nWood: {1}\nMagic Stone: {2}\nBuild Time: {3}", model.armySize, wood, magicStone, buildTime); }
// ------------------------------------------------------------------------------------------------------------------------------------------------------- // Planning Stage // Check whether we can train this unit in this planning phase public bool IsUnitTrainable(UnitType type, int remSupply, BuildingType plannedBuilding) { UnitPurchaseModel model = UnitPurchaseModelFactory.Create(type); bool prerequisite = GetBuildPlotController().IsComplete(model.prerequisite) || model.prerequisite == plannedBuilding; bool enoughSupply = remSupply >= model.armySize; return(prerequisite && enoughSupply); }
public void TryTrainNextUnit() { if (!trainer.isTraining) { UnitPurchaseModel model = trainingQueue.Dequeue(); trainer.StartTraining(model); Debug.Log(QueueStatus()); } }
// ------------------------------------------------------------------------------------------------------------------------------------------------------- // Execution Phase // Gets command for given Unit type public GameBehaviourCommand GetUnitToAddToQueue(UnitType type) { UnitPurchaseModel model = UnitPurchaseModelFactory.Create(type); // update internal state startingUnits.Add(type); // add command to list return(ArmyCommandFactory.CreateBuyUnitCommand(type, PlayerType.AI)); }
public void StartTraining(UnitPurchaseModel model) { this.model = model; isTraining = true; requiredTicks = model.trainingTime; currentTick = 0; GetGameLog().Log(string.Format("Started training {0}", model.unitType.ToString().ToLower())); TimeTickSystem.OnTick += UnitTrainer_OnTick; }
private void PembelianBindingSource_AddingNew(object sender, AddingNewEventArgs e) { XPQuery <BranchModel> branch_coll = PembelianUnitOfWork.Query <BranchModel>(); UnitPurchaseModel unitPurchase = new UnitPurchaseModel(PembelianUnitOfWork) { branchid = branch_coll.FirstOrDefault(b => b.id == Login.User.current_branch.id), tanggal_pembelian = DateTime.Now, created_at = DateTime.Now, created_by = Login.User.username }; e.NewObject = unitPurchase; }
// Get highest priority not-already built building, returns null if all are built. public BuildingModel PlanBuilding(UnitPriorities unitPriorities) { // check if all buildings are built? // -> prevent unnecessary checks Dictionary <UnitType, float> priorities = unitPriorities.priorities; List <UnitType> unitTypesSortedByPriority = new List <UnitType>(); UnitType maxPriorityType = UnitType.SWORDSMAN; float maxPriorityValue = -1f; // sort by priority while (unitTypesSortedByPriority.Count < priorities.Count) { foreach (KeyValuePair <UnitType, float> entry in priorities) { if (!unitTypesSortedByPriority.Contains(entry.Key) && entry.Value > maxPriorityValue) { maxPriorityType = entry.Key; maxPriorityValue = entry.Value; } } Debug.Log("adding " + maxPriorityType); unitTypesSortedByPriority.Add(maxPriorityType); maxPriorityValue = -1f; } // iterate over sorted list foreach (UnitType type in unitTypesSortedByPriority) { UnitPurchaseModel unitModel = UnitPurchaseModelFactory.Create(type); BuildingType buildingType = unitModel.prerequisite; if (!GetBuildPlotController().IsComplete(buildingType)) { BuildingModel buildingModel = BuildingModelFactory.Create(buildingType); // Update resource costs woodCost = buildingModel.buildCost.GetResourceAmount(ResourceType.WOOD); magicStoneCost = buildingModel.buildCost.GetResourceAmount(ResourceType.MAGIC_STONE); return(buildingModel); } } // No building to be built return(null); }
public override bool Execute() { Debug.Log("buy unit command executing"); ArmyController armyController = GetArmyController(); ResourceController resourceController = GetResourceController(); model = UnitPurchaseModelFactory.Create(unitType); // Check if prerequisite building has been built bool prerequisiteBuilt = GetBuildPlotController().IsComplete(model.prerequisite); if (!prerequisiteBuilt) { // abort Debug.LogError(string.Format("Can't construct {0}, as its prerequisite building {1} hasn't been constructed.", unitType, model.prerequisite)); GetGameLogController().Log(string.Format("Error: Can't construct {0}, as its prerequisite building {1} hasn't been constructed.", unitType, model.prerequisite)); return(false); } // Check supply bool supplyAvailable = armyController.CheckSupply(model); if (!supplyAvailable) { // abort Debug.LogError("no supply available"); GetGameLogController().Log("Error: Not enough supply to construct" + unitType); return(false); } // transaction succeeds if (resourceController.PayOutTransaction(model.buildCost)) { armyController.AddUnitToBuildQueue(model); } else // rejected { GetGameLogController().Log("Error: Not enough resources to construct" + unitType); return(false); } return(true); }
private void Simpan_Click(object sender, EventArgs e) { if (!HeaderValidator.Validate()) { return; } UnitPurchaseModel unitPurchase = (UnitPurchaseModel)PembelianBindingSource.Current; unitPurchase.updated_by = Login.User.username; unitPurchase.updated_at = DateTime.Now; PembelianUnitOfWork.CommitChanges(); string kode = "PB/" + DateTime.Now.Year.ToString() + "/" + AutoDealer.Additional.DB.GetColumnName((int)Login.User.current_branch.id) + "/"; kode_pembelian.Text = AutoDealer.Additional.DB.AutoIncrement(kode, unitPurchase.id); PembelianBindingSource.EndEdit(); PembelianUnitOfWork.CommitChanges(); DetailXtraTabControl.Visible = true; }
// queue up target army creation public Queue <AI_GameBehaviourCommand> GetArmyConstructionCommands(UnitMap targetMap, BuildingType plannedBuilding) { // calculate units that need to be trained Queue <AI_GameBehaviourCommand> armyCommands = new Queue <AI_GameBehaviourCommand>(); UnitMap unitsToBeConstructed = startingUnits.UnitsRequiredToBecome(targetMap); Debug.Log(unitsToBeConstructed.StatusString()); // iterate over required units and add the command to the queue foreach (KeyValuePair <UnitType, int> unitMapEntry in unitsToBeConstructed.units) { UnitType type = unitMapEntry.Key; UnitPurchaseModel model = UnitPurchaseModelFactory.Create(type); int numUnits = unitMapEntry.Value; while (numUnits > 0) { if (IsUnitTrainable(type, remainingSupply, plannedBuilding)) { GameBehaviourCommand command = GetUnitToAddToQueue(type); AI_GameBehaviourCommand aiCommand = new AI_GameBehaviourCommand(command, model.buildCost); armyCommands.Enqueue(aiCommand); numUnits--; remainingSupply -= model.armySize; } else { Debug.LogError("Bad error -- cant create unit that was planned to be created"); break; } } } return(armyCommands); }
// generate target army for this combat phase public UnitMap GenerateTargetArmy(UnitPriorities unitPriorities, BuildingType plannedBuilding) { UnitMap targetArmy = new UnitMap(startingUnits); int remainingSupplyCopy = remainingSupply; // while army not full (won't cause any issues as all units currently have 1 or 2 as their supplyCost, may need changes in future) while (remainingSupplyCopy > 0) { UnitPurchaseModel model = null; while (model == null) { model = RandomlySelectUnit(unitPriorities); } UnitType type = model.unitType; if (IsUnitTrainable(type, remainingSupplyCopy, plannedBuilding)) { requiredWood += model.buildCost.GetResourceAmount(ResourceType.WOOD); requiredMagicStone += model.buildCost.GetResourceAmount(ResourceType.MAGIC_STONE); remainingSupplyCopy -= model.armySize; targetArmy.Add(type); } ; } // check if supply has gone negative if (remainingSupplyCopy != 0) { Debug.LogError("supply < 0? (=" + remainingSupplyCopy + ")"); } Debug.Log(targetArmy.StatusString()); return(targetArmy); }
public void AddUnit(UnitPurchaseModel model) { queue.AddToQueue(model); }
public void AddToQueue(UnitPurchaseModel model) { trainingQueue.Enqueue(model); }
public bool CheckSupply(UnitPurchaseModel model) { return((model.armySize + currentSupply) <= maxSupply); }
// To be called by UnitTrainer public void AddCompleteUnit(UnitPurchaseModel model) { unitMap.Add(model.unitType); }
// done at start of construction -> before unit is "finished"! public void ReserveSupply(UnitPurchaseModel model) { currentSupply += model.armySize; }
public void AddUnitToBuildQueue(UnitPurchaseModel model) { army.ReserveSupply(model); UpdateSupplyView(); army.AddUnit(model); }
public bool CheckSupply(UnitPurchaseModel model) { return(army.CheckSupply(model)); }
public void AddCompleteUnit(UnitPurchaseModel model) { army.AddCompleteUnit(model); UpdateUnitView(model.unitType); }
public void TrainUnit(UnitPurchaseModel model) { trainer.StartTraining(model); }