Ejemplo n.º 1
0
    void StartTrade()
    {
        for (int i = 0; i < tradeGoods.Count; i++)
        {
            Resource       currentTradeGood          = tradeGoods[i];
            ResourceStatus resourceStatusOfOtherCity = this.targetCity.GetResourceStatusByType(currentTradeGood.resourceType);
            if (resourceStatusOfOtherCity.status == RESOURCE_STATUS.SCARCE)
            {
                int costPerResourceUnit      = this.GetCostPerResourceUnit(currentTradeGood.resourceType);
                int totalCostOfWholeResource = resourceStatusOfOtherCity.amount * costPerResourceUnit;
                int numOfResourcesAfforded   = (int)Math.Floor((double)(targetCity.goldCount / costPerResourceUnit));

                if (numOfResourcesAfforded > currentTradeGood.resourceQuantity)
                {
                    numOfResourcesAfforded = currentTradeGood.resourceQuantity;
                }

                if (numOfResourcesAfforded <= 0)
                {
                    //target city cannot afford to buy the offered resource
                    this.targetCity.cityLogs += GameManager.Instance.currentDay.ToString() + ": Merchant from " + this.citizen.city.cityName + " arrived, offering "
                                                + currentTradeGood.resourceType.ToString() + ", but rejected because the city cannot afford to buy.\n\n";
                    continue;
                }

                DECISION tradeCityDecision = DECISION.NONE;
                if (targetCity.kingdomTile.kingdom.id != this.citizen.city.id)
                {
                    tradeCityDecision = this.targetCity.kingdomTile.kingdom.lord.ComputeDecisionBasedOnPersonality(LORD_EVENTS.TRADE, this.citizen.city.kingdomTile.kingdom.lord);
                }

                if (tradeCityDecision == DECISION.NICE || tradeCityDecision == DECISION.NONE)
                {
                    this.ProcessTransaction(currentTradeGood.resourceType, numOfResourcesAfforded, numOfResourcesAfforded * costPerResourceUnit);
                    this.citizen.city.cityLogs += GameManager.Instance.currentDay.ToString() + ": Merchant has sold [FF0000]" + numOfResourcesAfforded + " " + currentTradeGood.resourceType.ToString() + "[-] in exchange for [FF0000]"
                                                  + (numOfResourcesAfforded * costPerResourceUnit).ToString() + " GOLD[-].\n\n";

                    this.targetCity.cityLogs += GameManager.Instance.currentDay.ToString() + ": City has bought [FF0000]" + numOfResourcesAfforded + " " + currentTradeGood.resourceType.ToString() + "[-] in exchange for [FF0000]"
                                                + (numOfResourcesAfforded * costPerResourceUnit).ToString() + " GOLD[-].\n\n";

                    UserInterfaceManager.Instance.externalAffairsLogList [UserInterfaceManager.Instance.externalAffairsLogList.Count - 1] += GameManager.Instance.currentDay.ToString() + ": TRADE: " + this.targetCity.kingdomTile.kingdom.lord.name + " ACCEPTED the trade.\n\n";
                }
                else
                {
                    this.citizen.city.kingdomTile.kingdom.lord.AdjustLikeness(this.targetCity.kingdomTile.kingdom.lord, DECISION.NEUTRAL, DECISION.RUDE, LORD_EVENTS.TRADE, true);
                    this.targetCity.kingdomTile.kingdom.lord.AdjustLikeness(this.citizen.city.kingdomTile.kingdom.lord, DECISION.RUDE, DECISION.NEUTRAL, LORD_EVENTS.TRADE, false);

                    this.citizen.city.cityLogs += GameManager.Instance.currentDay.ToString() + ": Trade was rejected by lord of city [FF0000]" + this.targetCity.cityName + "[-].\n\n";
                    this.targetCity.cityLogs   += GameManager.Instance.currentDay.ToString() + ": Trade from " + this.citizen.city.cityName + " was rejected this city's lord.\n\n";

                    UserInterfaceManager.Instance.externalAffairsLogList [UserInterfaceManager.Instance.externalAffairsLogList.Count - 1] += GameManager.Instance.currentDay.ToString() + ": TRADE: " + this.targetCity.kingdomTile.kingdom.lord.name + " REJECTED the trade.\n\n";
                }
            }
            else
            {
                this.targetCity.cityLogs += GameManager.Instance.currentDay.ToString() + ": Merchant from " + this.citizen.city.cityName + " arrived, offering "
                                            + currentTradeGood.resourceType.ToString() + ", but rejected since the city does not need more of that resource.\n\n";
            }
        }
    }
Ejemplo n.º 2
0
 public CooperateEvents(int lord1Id, DECISION lord1Decision, int lord2Id, DECISION lord2Decision, LORD_EVENTS eventType, int daysLeft)
 {
     this.lord1Id       = lord1Id;
     this.lord1Decision = lord1Decision;
     this.lord2Id       = lord2Id;
     this.lord2Decision = lord2Decision;
     this.eventType     = eventType;
     this.daysLeft      = daysLeft;
 }
 public RelationshipKingdoms(KingdomTest kingdom, DECISION previousDecision, int like)
 {
     //		this.id = id;
     this.kingdom          = kingdom;
     this.previousDecision = previousDecision;
     this.like             = like;
     this.isFirstEncounter = true;
     this.lordRelationship = LORD_RELATIONSHIP.NEUTRAL;
     this.isAdjacent       = false;
     this.isAtWar          = false;
 }
Ejemplo n.º 4
0
    internal void CooperateEvent2()
    {
        List <KingdomTileTest> kingdoms = new List <KingdomTileTest> ();

        kingdoms.AddRange(this.kingdoms);


        if (kingdoms.Count > 1)
        {
            kingdoms = Utilities.Shuffle(kingdoms);

            /*
             * A huge monster guarding some treasure is discovered.
             * The Lords must cooperate to defeat it. If they cooperate, the monster is defeated and they are able to split the treasure.
             * One can be betrayed by unleashing the monster onto the other Lord's realm while the other takes all the treasure.
             * If both attempt to do this, the monster stays and the treasure remains guarded.
             */

            int  randomLord1 = UnityEngine.Random.Range(0, kingdoms.Count);
            Lord lord1       = kingdoms [randomLord1].kingdom.lord;
            kingdoms.RemoveAt(randomLord1);

            int  randomLord2 = UnityEngine.Random.Range(0, kingdoms.Count);
            Lord lord2       = kingdoms [randomLord2].kingdom.lord;
            kingdoms.RemoveAt(randomLord2);

            DECISION lord1Decision = lord1.ComputeDecisionBasedOnPersonality(LORD_EVENTS.COOPERATE2, lord2);
            DECISION lord2Decision = lord2.ComputeDecisionBasedOnPersonality(LORD_EVENTS.COOPERATE2, lord1);

            if (lord1Decision == DECISION.NICE && lord2Decision == DECISION.NICE)
            {
            }
            else if (lord1Decision == DECISION.NICE && lord2Decision == DECISION.RUDE)
            {
            }
            else if (lord1Decision == DECISION.RUDE && lord2Decision == DECISION.NICE)
            {
            }
            else if (lord1Decision == DECISION.RUDE && lord2Decision == DECISION.RUDE)
            {
            }

            UserInterfaceManager.Instance.externalAffairsLogList[UserInterfaceManager.Instance.externalAffairsLogList.Count - 1] += this.currentDay.ToString() + ": COOPERATE EVENT 2: " + lord1.name + " decided to be " + lord1Decision.ToString()
                                                                                                                                    + ". " + lord2.name + " decided to be " + lord2Decision.ToString() + ".\n\n";

            pendingCooperateEvents.Add(new CooperateEvents(lord1.id, lord1Decision, lord2.id, lord2Decision, LORD_EVENTS.COOPERATE2, (currentDay + 5)));

            Utilities.cooperate2Count++;
        }
        else
        {
            Debug.Log("THERE IS NOT ENOUGH KINGDOMS! CAN'T COOPERATE (2)");
        }
    }
Ejemplo n.º 5
0
    public Relationship(Lord lord, DECISION previousDecision, int like)
    {
//		this.id = id;
        this.lord             = lord;
        this.previousDecision = previousDecision;
        this.like             = like;
        this.isFirstEncounter = true;
        this.lordRelationship = LORD_RELATIONSHIP.NEUTRAL;
        this.isAdjacent       = false;
        this.isAtWar          = false;
    }
Ejemplo n.º 6
0
    public override void AgentAction(float[] vectorAction, string textAction)
    {
        DECISION decision = (DECISION)vectorAction[0];

        switch (decision)
        {
        case DECISION.AttackEnemy1:
            battleManager.selectedAction = self.skillList.Find(skill => skill.name == "Attack");
            battleManager.targetUnit     = enemy1;
            break;

        case DECISION.AttackEnemy2:
            battleManager.selectedAction = self.skillList.Find(skill => skill.name == "Attack");
            battleManager.targetUnit     = enemy2;
            break;

        case DECISION.DoubleEnemy1:
            battleManager.selectedAction = self.skillList.Find(skill => skill.name == "Double");
            battleManager.targetUnit     = enemy1;
            break;

        case DECISION.DoubleEnemy2:
            battleManager.selectedAction = self.skillList.Find(skill => skill.name == "Double");
            battleManager.targetUnit     = enemy2;
            break;

        case DECISION.PoisonEnemy1:
            battleManager.selectedAction = self.skillList.Find(skill => skill.name == "Poison");
            battleManager.targetUnit     = enemy1;
            break;

        case DECISION.PoisonEnemy2:
            battleManager.selectedAction = self.skillList.Find(skill => skill.name == "Poison");
            battleManager.targetUnit     = enemy2;
            break;

        case DECISION.StunEnemy1:
            battleManager.selectedAction = self.skillList.Find(skill => skill.name == "Stun");
            battleManager.targetUnit     = enemy1;
            if (decisionLog)
            {
                StatusEffect stunEffect = enemy1.effects.FindLast(effect => effect.text == "Stunned");
                if (stunEffect != null && stunEffect.TurnsLeft == 1 && myLogIndex != -1)
                {
                    decisionLog.logs[myLogIndex].coordinatedStuns++;
                }
            }
            break;

        case DECISION.StunEnemy2:
            battleManager.selectedAction = self.skillList.Find(skill => skill.name == "Stun");
            battleManager.targetUnit     = enemy2;
            if (decisionLog)
            {
                StatusEffect stunEffect = enemy2.effects.FindLast(effect => effect.text == "Stunned");
                if (stunEffect != null && stunEffect.TurnsLeft == 1 && myLogIndex != -1)
                {
                    decisionLog.logs[myLogIndex].coordinatedStuns++;
                }
            }
            break;

        case DECISION.BlindEnemy1:
            battleManager.selectedAction = self.skillList.Find(skill => skill.name == "Blind");
            battleManager.targetUnit     = enemy1;
            if (decisionLog)
            {
                StatusEffect blindEffect = enemy1.effects.FindLast(effect => effect.text == "Blinded");
                if (blindEffect != null && blindEffect.TurnsLeft == 1 && myLogIndex != -1)
                {
                    decisionLog.logs[myLogIndex].coordinatedBlinds++;
                }
            }
            break;

        case DECISION.BlindEnemy2:
            battleManager.selectedAction = self.skillList.Find(skill => skill.name == "Blind");
            battleManager.targetUnit     = enemy2;
            if (decisionLog)
            {
                StatusEffect blindEffect = enemy2.effects.FindLast(effect => effect.text == "Blinded");
                if (blindEffect != null && blindEffect.TurnsLeft == 1 && myLogIndex != -1)
                {
                    decisionLog.logs[myLogIndex].coordinatedBlinds++;
                }
            }
            break;

        case DECISION.BlockSelf:
            battleManager.selectedAction = self.skillList.Find(skill => skill.name == "Block");
            battleManager.targetUnit     = self;
            break;

        case DECISION.HealSelf:
            battleManager.selectedAction = self.skillList.Find(skill => skill.name == "Heal");
            battleManager.targetUnit     = self;
            break;

        case DECISION.HealAlly:
            battleManager.selectedAction = self.skillList.Find(skill => skill.name == "Heal");
            battleManager.targetUnit     = ally;
            if (decisionLog && myLogIndex != -1)
            {
                decisionLog.logs[myLogIndex].healedAlly++;
                // Same health percentage the heuristic uses to classify unit as vulnerable
                if (ally.CurHP < 0.65 * ally.MaxHP)
                {
                    decisionLog.logs[myLogIndex].healedVulnerableAlly++;
                }
                // The heal skill heals based on max hp percentage of the target
                // For consistency's sake the comparison also uses health percentage
                if (ally.CurHP / ally.MaxHP < self.CurHP / self.MaxHP)
                {
                    decisionLog.logs[myLogIndex].healedWeakerAlly++;
                }
            }
            break;
        }

        // Debug.Log("Calculated reward at action = " + GetCumulativeReward());
        battleManager.TargetSelected();
    }