private void HeroRefresh(AgeTransform tableitem, Unit hero, int index)
    {
        HeroCard component = tableitem.GetComponent <HeroCard>();

        component.Bind(hero, this.Empire, base.gameObject);
        component.RefreshContent(false, false);
        if (DepartmentOfEducation.IsInjured(hero) || DepartmentOfEducation.IsLocked(hero) || DepartmentOfIntelligence.IsHeroInfiltrating(hero, this.Empire) || DepartmentOfEducation.IsCaptured(hero))
        {
            component.GetComponent <AgeTransform>().Enable = false;
            component.Foreground.Alpha = 0.8f;
        }
        else if (hero.Garrison != null && hero.Garrison.IsInEncounter)
        {
            component.GetComponent <AgeTransform>().Enable = false;
            component.Foreground.Alpha = 0.8f;
        }
        else if (DepartmentOfEducation.CheckGarrisonAgainstSiege(hero, hero.Garrison) && !DepartmentOfEducation.CheckHeroExchangeAgainstSiege(hero.Garrison, this.destination))
        {
            component.GetComponent <AgeTransform>().Enable = false;
            component.Foreground.Alpha = 0.8f;
        }
        else
        {
            component.GetComponent <AgeTransform>().Enable = true;
            component.Foreground.Alpha = 0f;
        }
        if (this.isASpySelection && !hero.CheckUnitAbility(UnitAbility.ReadonlySpy, -1))
        {
            component.GetComponent <AgeTransform>().Enable = false;
            component.Foreground.Alpha = 0.8f;
        }
    }
예제 #2
0
    internal virtual void OnEmpireEliminated(global::Empire empire, bool authorized)
    {
        DepartmentOfDefense agency = base.GetAgency <DepartmentOfDefense>();

        if (agency != null)
        {
            agency.OnEmpireEliminated(empire, authorized);
        }
        DepartmentOfEducation agency2 = base.GetAgency <DepartmentOfEducation>();

        if (agency2 != null)
        {
            agency2.OnEmpireEliminated(empire, authorized);
        }
        DepartmentOfTheInterior agency3 = base.GetAgency <DepartmentOfTheInterior>();

        if (agency3 != null)
        {
            agency3.OnEmpireEliminated(empire, authorized);
        }
        DepartmentOfCreepingNodes agency4 = base.GetAgency <DepartmentOfCreepingNodes>();

        if (agency4 != null)
        {
            agency4.OnEmpireEliminated(empire, authorized);
        }
        DepartmentOfTheTreasury agency5 = base.GetAgency <DepartmentOfTheTreasury>();

        if (agency5 != null)
        {
            agency5.OnEmpireEliminated(empire, authorized);
        }
    }
예제 #3
0
 private void OnChangeContractTermLineQuantity(ContractTermLine contractTermLine)
 {
     if (this.DiplomaticContract == null)
     {
         Diagnostics.LogWarning("Diplomatic contract is null");
         return;
     }
     if (contractTermLine.ContractTerm is DiplomaticTermResourceExchange)
     {
         DiplomaticTermResourceExchange diplomaticTermResourceExchange = contractTermLine.ContractTerm as DiplomaticTermResourceExchange;
         DiplomaticTermResourceExchange term = new DiplomaticTermResourceExchange((DiplomaticTermResourceExchangeDefinition)diplomaticTermResourceExchange.Definition, diplomaticTermResourceExchange.EmpireWhichProposes, diplomaticTermResourceExchange.EmpireWhichProvides, diplomaticTermResourceExchange.EmpireWhichReceives, diplomaticTermResourceExchange.ResourceName, contractTermLine.CurrentQuantity);
         DiplomaticTermChange[]         diplomaticTermChanges = new DiplomaticTermChange[]
         {
             DiplomaticTermChange.Refresh(term, contractTermLine.ContractTerm.Index)
         };
         OrderChangeDiplomaticContractTermsCollection order = new OrderChangeDiplomaticContractTermsCollection(this.DiplomaticContract, diplomaticTermChanges);
         Ticket ticket;
         base.PlayerController.PostOrder(order, out ticket, new EventHandler <TicketRaisedEventArgs>(this.OnOrderChangeDiplomaticContractTermsCollectionResponse));
     }
     else
     {
         if (!(contractTermLine.ContractTerm is DiplomaticTermBoosterExchange))
         {
             Diagnostics.LogError("Trying to change quantity on a term that doesn't have any quantity.");
             return;
         }
         DiplomaticTermBoosterExchange termBoosterExchange = contractTermLine.ContractTerm as DiplomaticTermBoosterExchange;
         DepartmentOfEducation         agency = termBoosterExchange.EmpireWhichProvides.GetAgency <DepartmentOfEducation>();
         List <GameEntityGUID>         list   = (from match in agency
                                                 where match.Constructible.Name == termBoosterExchange.BoosterDefinitionName
                                                 select match into selectedBooster
                                                 select selectedBooster.GUID).ToList <GameEntityGUID>();
         int num = (int)contractTermLine.CurrentQuantity;
         if (num < list.Count)
         {
             list.RemoveRange(num, list.Count - num);
             list.TrimExcess();
         }
         GameEntityGUID[] boosterGUIDs       = list.ToArray();
         DiplomaticTermBoosterExchange term2 = new DiplomaticTermBoosterExchange((DiplomaticTermBoosterExchangeDefinition)termBoosterExchange.Definition, termBoosterExchange.EmpireWhichProposes, termBoosterExchange.EmpireWhichProvides, termBoosterExchange.EmpireWhichReceives, boosterGUIDs, termBoosterExchange.BoosterDefinitionName);
         DiplomaticTermChange[]        diplomaticTermChanges2 = new DiplomaticTermChange[]
         {
             DiplomaticTermChange.Refresh(term2, contractTermLine.ContractTerm.Index)
         };
         OrderChangeDiplomaticContractTermsCollection order2 = new OrderChangeDiplomaticContractTermsCollection(this.DiplomaticContract, diplomaticTermChanges2);
         Ticket ticket2;
         base.PlayerController.PostOrder(order2, out ticket2, new EventHandler <TicketRaisedEventArgs>(this.OnOrderChangeDiplomaticContractTermsCollectionResponse));
     }
 }
예제 #4
0
    private static float UtilityFunc_WorldSpy(SeasonEffect aiEvaluableElement, InterpreterContext context, float aiParameterValue, AIHeuristicAnalyser.Context debugContext)
    {
        global::Empire empire = context.Get("Empire") as global::Empire;

        Diagnostics.Assert(empire != null);
        float num = 0f;
        DepartmentOfEducation agency = empire.GetAgency <DepartmentOfEducation>();

        for (int i = 0; i < agency.Heroes.Count; i++)
        {
            num += agency.Heroes[i].GetPropertyValue("NetInfiltrationPoint");
        }
        float num2 = num * 0.05f;

        return(aiParameterValue * num2);
    }
예제 #5
0
    public void DisableIfLockedHeroAssigned()
    {
        int num = 0;

        if (this.Army.Hero != null)
        {
            num = DepartmentOfEducation.LockedRemainingTurns(this.Army.Hero);
        }
        if (num > 0)
        {
            this.AgeTransform.Enable = false;
            this.AgeTransform.StopSearchingForTooltips = true;
            this.AgeTransform.AgeTooltip.Content       = AgeLocalizer.Instance.LocalizeString("%HeroAssignmentLockedTurnsDescription").Replace("$NumberOfTurns", num.ToString());
            this.HeroCard.HeroPortrait.TintColor       = new Color(1f, 0.5f, 0.5f, 1f);
        }
    }
예제 #6
0
 private void OrderSplitUnit(object sender, TicketRaisedEventArgs e)
 {
     if (e.Result == PostOrderResponse.Processed)
     {
         DepartmentOfEducation agency = base.Commander.Empire.GetAgency <DepartmentOfEducation>();
         if (agency.Heroes.Count > 0)
         {
             OrderChangeHeroAssignment order = new OrderChangeHeroAssignment(base.Commander.Empire.Index, agency.Heroes[0].GUID, (e.Order as OrderTransferGarrisonToNewArmy).ArmyGuid);
             base.Commander.Empire.PlayerControllers.AI.PostOrder(order);
         }
         AILayer_ArmyManagement layer = base.Commander.AIPlayer.GetEntity <AIEntity_Empire>().GetLayer <AILayer_ArmyManagement>();
         if (layer != null)
         {
             layer.AssignJoblessArmies();
         }
     }
 }
예제 #7
0
    public override bool TryAllocateTo(Empire empire, float quantity, params object[] parameters)
    {
        if (this.GameEntityGUIDs == null)
        {
            return(false);
        }
        if ((float)this.GameEntityGUIDs.Length < quantity)
        {
            return(false);
        }
        DepartmentOfEducation agency = empire.GetAgency <DepartmentOfEducation>();

        if (agency != null)
        {
            IDatabase <BoosterDefinition> database = Databases.GetDatabase <BoosterDefinition>(false);
            BoosterDefinition             constructibleElement;
            if (database != null && database.TryGetValue(this.BoosterDefinitionName, out constructibleElement))
            {
                int num  = (int)quantity;
                int num2 = this.GameEntityGUIDs.Length - 1;
                while (num > 0 && num2 >= 0)
                {
                    agency.AddVaultItem(new VaultItem(this.GameEntityGUIDs[num2], constructibleElement));
                    num--;
                    num2--;
                }
                int num3 = this.GameEntityGUIDs.Length - (int)quantity;
                if (num3 == 0)
                {
                    this.GameEntityGUIDs = null;
                }
                else
                {
                    GameEntityGUID[] array = new GameEntityGUID[num3];
                    Array.Copy(this.GameEntityGUIDs, array, num3);
                    this.GameEntityGUIDs = array;
                }
                return(true);
            }
        }
        return(false);
    }
예제 #8
0
    public virtual bool IsAcceptingHeroAssignments(out Garrison.IsAcceptingHeroAssignmentReasonsEnum reason)
    {
        DepartmentOfEducation agency = this.Empire.GetAgency <DepartmentOfEducation>();

        if (agency != null && agency.Heroes.Count == 0)
        {
            reason = Garrison.IsAcceptingHeroAssignmentReasonsEnum.NoHeroes;
            return(false);
        }
        if (this.standardUnits != null)
        {
            for (int i = 0; i < this.standardUnits.Count; i++)
            {
                if (this.standardUnits[i].UnitDesign != null && this.standardUnits[i].UnitDesign.Tags.Contains(DownloadableContent9.TagSolitary))
                {
                    reason = Garrison.IsAcceptingHeroAssignmentReasonsEnum.IsSolitary;
                    return(false);
                }
            }
        }
        reason = Garrison.IsAcceptingHeroAssignmentReasonsEnum.None;
        return(true);
    }
예제 #9
0
    public void ClearFortressUnits()
    {
        IGameEntityRepositoryService service = this.gameService.Game.Services.GetService <IGameEntityRepositoryService>();

        if (this.StandardUnits.Count > 0)
        {
            Diagnostics.LogWarning("We are swapping a city which is not empty; this should not happen. All remaining units will be scraped.");
            while (this.StandardUnits.Count > 0)
            {
                Unit unit = this.StandardUnits[0];
                this.RemoveUnit(unit);
                service.Unregister(unit);
                unit.Dispose();
            }
        }
        if (this.Hero != null)
        {
            DepartmentOfEducation agency = this.Empire.GetAgency <DepartmentOfEducation>();
            if (agency != null)
            {
                agency.UnassignHero(this.Hero);
            }
        }
    }
예제 #10
0
    private void FindHeroSpecialtyELCP(Unit hero)
    {
        List <UnitSkill> list = new List <UnitSkill>();

        DepartmentOfEducation.FillAvailableUnitSkills(hero, ref list);
        using (InterpreterContext.InterpreterSession interpreterSession = new InterpreterContext.InterpreterSession(hero))
        {
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].Prerequisites != null && list[i].Prerequisites.Length != 0 && hero.IsSkillUnlocked(list[i].Name))
                {
                    int num = hero.GetSkillLevel(list[i].Name) + 1;
                    foreach (IAIParameter <InterpreterContext> iaiparameter in this.constructibleEvaluationAIHelper.GetAIParameters(list[i]))
                    {
                        int num2 = Array.IndexOf <string>(AILayer_HeroAssignation.HeroAssignationTypeNames, iaiparameter.Name.ToString());
                        if (num2 >= 0)
                        {
                            for (int j = 0; j < num; j++)
                            {
                                float num3 = iaiparameter.GetValue(interpreterSession.Context);
                                if (j > 0)
                                {
                                    num3 *= 0.5f;
                                }
                                this.LongTermSpecialtyFitness[num2] = AILayer.Boost(this.LongTermSpecialtyFitness[num2], num3);
                            }
                        }
                    }
                }
            }
            List <UnitAbilityReference> list2 = new List <UnitAbilityReference>();
            if (hero.UnitDesign.UnitBodyDefinition.UnitAbilities != null)
            {
                list2.AddRange(hero.UnitDesign.UnitBodyDefinition.UnitAbilities.ToList <UnitAbilityReference>());
            }
            if ((hero.UnitDesign as UnitProfile).ProfileAbilityReferences != null)
            {
                list2.AddRange((hero.UnitDesign as UnitProfile).ProfileAbilityReferences.ToList <UnitAbilityReference>());
            }
            list2.Add(new UnitAbilityReference(UnitAbility.ReadonlyLastStand, 0));
            using (IEnumerator <KeyValuePair <StaticString, int> > enumerator2 = hero.EnumerateUnitAbilities().GetEnumerator())
            {
                while (enumerator2.MoveNext())
                {
                    KeyValuePair <StaticString, int> keyValuePair = enumerator2.Current;
                    int num4 = list2.FindIndex((UnitAbilityReference r) => r.Name == keyValuePair.Key);
                    if (num4 >= 0)
                    {
                        float       a    = Mathf.Max(1f, (float)(list2[num4].Level + 1));
                        float       b    = Mathf.Max(1f, (float)(keyValuePair.Value + 1));
                        float       num5 = Mathf.Min(a, b);
                        UnitAbility element;
                        if (this.unitAbilityDatabase.TryGetValue(keyValuePair.Key, out element))
                        {
                            foreach (IAIParameter <InterpreterContext> iaiparameter2 in this.constructibleEvaluationAIHelper.GetAIParameters(element))
                            {
                                int num6 = Array.IndexOf <string>(AILayer_HeroAssignation.HeroAssignationTypeNames, iaiparameter2.Name.ToString());
                                if (num6 >= 0)
                                {
                                    int num7 = 0;
                                    while ((float)num7 < num5)
                                    {
                                        float num8 = iaiparameter2.GetValue(interpreterSession.Context);
                                        if (num7 > 0)
                                        {
                                            num8 *= 0.5f;
                                        }
                                        this.LongTermSpecialtyFitness[num6] = AILayer.Boost(this.LongTermSpecialtyFitness[num6], num8);
                                        num7++;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
예제 #11
0
    private void FindHeroSpecialty(Unit hero)
    {
        Diagnostics.Log("======================================================================================");
        Diagnostics.Log("ELCP {0} FindHeroSpecialty", new object[]
        {
            hero.Name
        });
        float            num  = 0f;
        List <UnitSkill> list = new List <UnitSkill>();

        DepartmentOfEducation.FillAvailableUnitSkills(hero, ref list);
        using (InterpreterContext.InterpreterSession interpreterSession = new InterpreterContext.InterpreterSession(hero))
        {
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].Prerequisites != null && list[i].Prerequisites.Length != 0)
                {
                    Diagnostics.Log("checking skill {0}, num {1}", new object[]
                    {
                        list[i].Name,
                        num
                    });
                    num += 1f;
                    float num2 = 1f;
                    if (hero.IsSkillUnlocked(list[i].Name))
                    {
                        int num3 = hero.GetSkillLevel(list[i].Name) + 1;
                        num  += (float)num3;
                        num2 += (float)num3;
                        Diagnostics.Log("skill unlocked, levelfactor {0}", new object[]
                        {
                            num2
                        });
                    }
                    foreach (IAIParameter <InterpreterContext> iaiparameter in this.constructibleEvaluationAIHelper.GetAIParameters(list[i]))
                    {
                        int num4 = Array.IndexOf <string>(AILayer_HeroAssignation.HeroAssignationTypeNames, iaiparameter.Name.ToString());
                        if (num4 >= 0)
                        {
                            this.LongTermSpecialtyFitness[num4] += iaiparameter.GetValue(interpreterSession.Context) * num2;
                            Diagnostics.Log("ltspecialiaty {0} + {1} to {2}", new object[]
                            {
                                num4,
                                iaiparameter.GetValue(interpreterSession.Context) * num2,
                                this.LongTermSpecialtyFitness[num4]
                            });
                        }
                    }
                }
            }
            foreach (KeyValuePair <StaticString, int> keyValuePair in hero.EnumerateUnitAbilities())
            {
                float num5 = Mathf.Max(1f, (float)(keyValuePair.Value + 1));
                Diagnostics.Log("checking ability {0} {1}/{2}, num {3}", new object[]
                {
                    keyValuePair.Key,
                    keyValuePair.Value,
                    num5,
                    num
                });
                bool        flag = false;
                UnitAbility element;
                if (this.unitAbilityDatabase.TryGetValue(keyValuePair.Key, out element))
                {
                    foreach (IAIParameter <InterpreterContext> iaiparameter2 in this.constructibleEvaluationAIHelper.GetAIParameters(element))
                    {
                        int num6 = Array.IndexOf <string>(AILayer_HeroAssignation.HeroAssignationTypeNames, iaiparameter2.Name.ToString());
                        if (num6 >= 0)
                        {
                            this.LongTermSpecialtyFitness[num6] += iaiparameter2.GetValue(interpreterSession.Context) * num5;
                            Diagnostics.Log("ltspecialiaty {0} + {1} to {2}", new object[]
                            {
                                num6,
                                iaiparameter2.GetValue(interpreterSession.Context) * num5,
                                this.LongTermSpecialtyFitness[num6]
                            });
                            flag = true;
                        }
                    }
                }
                if (flag)
                {
                    num += num5;
                }
            }
        }
        Diagnostics.Log("+++++++++++++++++++");
        for (int j = 0; j < this.LongTermSpecialtyFitness.Length; j++)
        {
            Diagnostics.Log("final specialty {0}: {1}/{2} = {3}", new object[]
            {
                j,
                this.LongTermSpecialtyFitness[j],
                num,
                this.LongTermSpecialtyFitness[j] / num
            });
            this.LongTermSpecialtyFitness[j] /= num;
        }
    }
예제 #12
0
    bool IHeroManagementService.TryAllocateSkillPoints(Unit unit)
    {
        if (unit == null)
        {
            throw new ArgumentNullException("unit");
        }
        UnitProfile unitProfile = unit.UnitDesign as UnitProfile;

        if (unitProfile == null || !unitProfile.IsHero)
        {
            return(false);
        }
        int num = (int)Math.Floor((double)(unit.GetPropertyValue(SimulationProperties.MaximumSkillPoints) - unit.GetPropertyValue(SimulationProperties.SkillPointsSpent)));

        if (num <= 0)
        {
            return(false);
        }
        if (unitProfile.UnitSkillAllocationSchemeReference == null || StaticString.IsNullOrEmpty(unitProfile.UnitSkillAllocationSchemeReference))
        {
            return(false);
        }
        IDatabase <Droplist> database = Databases.GetDatabase <Droplist>(false);

        if (database == null)
        {
            return(false);
        }
        Droplist droplist;

        if (database.TryGetValue(unitProfile.UnitSkillAllocationSchemeReference, out droplist))
        {
            UnitSkill[] availableUnitSkills = DepartmentOfEducation.GetAvailableUnitSkills(unit);
            for (int i = 0; i < num; i++)
            {
                Droplist        droplist2;
                DroppableString droppableString = droplist.Pick(null, out droplist2, new object[0]) as DroppableString;
                if (droppableString != null)
                {
                    if (!string.IsNullOrEmpty(droppableString.Value))
                    {
                        StaticString     subcategory = droppableString.Value;
                        List <UnitSkill> list        = (from iterator in availableUnitSkills
                                                        where iterator.SubCategory == subcategory && DepartmentOfEducation.IsUnitSkillUnlockable(unit, iterator)
                                                        select iterator).ToList <UnitSkill>();
                        if (list.Count > 0)
                        {
                            while (list.Count > 0)
                            {
                                int index = UnityEngine.Random.Range(0, list.Count);
                                int num2  = 0;
                                if (unit.IsSkillUnlocked(list[index].Name))
                                {
                                    num2 = unit.GetSkillLevel(list[index].Name) + 1;
                                    int num3 = 0;
                                    if (list[index].UnitSkillLevels != null)
                                    {
                                        num3 = list[index].UnitSkillLevels.Length - 1;
                                    }
                                    if (num2 > num3)
                                    {
                                        list.Remove(list[index]);
                                        continue;
                                    }
                                }
                                unit.UnlockSkill(list[index].Name, num2);
                                num = (int)Math.Floor((double)(unit.GetPropertyValue(SimulationProperties.MaximumSkillPoints) - unit.GetPropertyValue(SimulationProperties.SkillPointsSpent)));
                                break;
                            }
                        }
                    }
                }
            }
        }
        return(true);
    }