Example #1
0
    public BuyUnitCommand(UnitType unitType, PlayerType playerType)
    {
        this.playerType = playerType;

        this.unitType = unitType;
        model         = null;
        Debug.Log("buy unit command created");
    }
Example #2
0
 public UnitTrainer(PlayerType playerType)
 {
     this.playerType = playerType;
     isTraining      = false;
     currentTick     = 0;
     requiredTicks   = 0;
     model           = null;
 }
Example #3
0
    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);
    }
Example #4
0
    // -------------------------------------------------------------------------------------------------------------------------------------------------------
    // 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());
        }
    }
Example #6
0
    // -------------------------------------------------------------------------------------------------------------------------------------------------------
    // 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));
    }
Example #7
0
    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;
    }
Example #8
0
        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);
    }
Example #10
0
    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);
    }
Example #11
0
        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;
        }
Example #12
0
    // 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);
    }
Example #13
0
    // 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);
    }
Example #14
0
 public void AddUnit(UnitPurchaseModel model)
 {
     queue.AddToQueue(model);
 }
 public void AddToQueue(UnitPurchaseModel model)
 {
     trainingQueue.Enqueue(model);
 }
Example #16
0
 public bool CheckSupply(UnitPurchaseModel model)
 {
     return((model.armySize + currentSupply) <= maxSupply);
 }
Example #17
0
 // To be called by UnitTrainer
 public void AddCompleteUnit(UnitPurchaseModel model)
 {
     unitMap.Add(model.unitType);
 }
Example #18
0
 // done at start of construction -> before unit is "finished"!
 public void ReserveSupply(UnitPurchaseModel model)
 {
     currentSupply += model.armySize;
 }
Example #19
0
 public void AddUnitToBuildQueue(UnitPurchaseModel model)
 {
     army.ReserveSupply(model);
     UpdateSupplyView();
     army.AddUnit(model);
 }
Example #20
0
 public bool CheckSupply(UnitPurchaseModel model)
 {
     return(army.CheckSupply(model));
 }
Example #21
0
 public void AddCompleteUnit(UnitPurchaseModel model)
 {
     army.AddCompleteUnit(model);
     UpdateUnitView(model.unitType);
 }
 public void TrainUnit(UnitPurchaseModel model)
 {
     trainer.StartTraining(model);
 }