Пример #1
0
 public void OnSquadTroopsReceived(Dictionary <string, int> troopsReceived, string donorId, string donorName)
 {
     if (this.Troops == null)
     {
         this.Troops = new List <SquadDonatedTroop>();
     }
     foreach (KeyValuePair <string, int> current in troopsReceived)
     {
         SquadDonatedTroop squadDonatedTroop = null;
         string            key = current.get_Key();
         int value             = current.get_Value();
         int i     = 0;
         int count = this.Troops.Count;
         while (i < count)
         {
             if (this.Troops[i].TroopUid == key)
             {
                 squadDonatedTroop = this.Troops[i];
                 break;
             }
             i++;
         }
         if (squadDonatedTroop == null)
         {
             squadDonatedTroop = new SquadDonatedTroop(key);
             this.Troops.Add(squadDonatedTroop);
         }
         squadDonatedTroop.AddSenderAmount(donorId, value);
         Service.Get <EventManager>().SendEvent(EventId.SquadTroopsReceived, current);
     }
     Service.Get <EventManager>().SendEvent(EventId.SquadTroopsReceivedFromDonor, donorName);
 }
Пример #2
0
        public static List <SquadDonatedTroop> GetSquadDonatedTroopsFromObject(object obj)
        {
            List <SquadDonatedTroop>    list       = new List <SquadDonatedTroop>();
            Dictionary <string, object> dictionary = obj as Dictionary <string, object>;

            if (dictionary != null)
            {
                foreach (KeyValuePair <string, object> current in dictionary)
                {
                    Dictionary <string, object> dictionary2 = current.get_Value() as Dictionary <string, object>;
                    if (dictionary2 != null)
                    {
                        string            key = current.get_Key();
                        SquadDonatedTroop squadDonatedTroop = new SquadDonatedTroop(key);
                        list.Add(squadDonatedTroop);
                        foreach (KeyValuePair <string, object> current2 in dictionary2)
                        {
                            string key2  = current2.get_Key();
                            int    value = Convert.ToInt32(current2.get_Value(), CultureInfo.InvariantCulture);
                            squadDonatedTroop.SenderAmounts.Add(key2, value);
                        }
                    }
                }
            }
            return(list);
        }
Пример #3
0
        protected void InitTroopGrid()
        {
            base.InitGrid();
            GamePlayer worldOwner = GameUtils.GetWorldOwner();
            List <SquadDonatedTroop> worldOwnerSquadBuildingTroops = SquadUtils.GetWorldOwnerSquadBuildingTroops();
            int count = worldOwnerSquadBuildingTroops.Count;

            if (count > 0)
            {
                Dictionary <string, string> dictionary = null;
                if (worldOwner.Squad != null)
                {
                    dictionary = new Dictionary <string, string>();
                    List <SquadMember> memberList = worldOwner.Squad.MemberList;
                    int i      = 0;
                    int count2 = memberList.Count;
                    while (i < count2)
                    {
                        SquadMember squadMember = memberList[i];
                        dictionary.Add(squadMember.MemberID, squadMember.MemberName);
                        i++;
                    }
                }
                StaticDataController staticDataController = Service.StaticDataController;
                for (int j = 0; j < count; j++)
                {
                    SquadDonatedTroop squadDonatedTroop = worldOwnerSquadBuildingTroops[j];
                    TroopTypeVO       troopTypeVO       = staticDataController.Get <TroopTypeVO>(squadDonatedTroop.TroopUid);
                    int totalAmount = squadDonatedTroop.GetTotalAmount();
                    if (totalAmount > 0)
                    {
                        string tooltipString = this.GetTooltipString(troopTypeVO, squadDonatedTroop, dictionary);
                        base.AddTroopItem(troopTypeVO, totalAmount, tooltipString);
                    }
                }
            }
            if (!this.inVisitMode && worldOwner.Squad != null && SquadUtils.GetDonatedTroopStorageUsedByWorldOwner() < this.buildingInfo.Storage)
            {
                this.AddTroopRequestItem();
            }
            else
            {
                this.requestResendCost = null;
            }
            base.RepositionGridItems();
        }
Пример #4
0
        private string GetTooltipString(TroopTypeVO troopVO, SquadDonatedTroop donation, Dictionary <string, string> squadMemberLookup)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(this.lang.Get("SQUAD_DONATED_TROOP", new object[]
            {
                LangUtils.GetTroopDisplayName(troopVO)
            }));
            int num  = 0;
            int num2 = 0;

            if (squadMemberLookup != null)
            {
                foreach (KeyValuePair <string, int> current in donation.SenderAmounts)
                {
                    string key   = current.Key;
                    int    value = current.Value;
                    string text;
                    if (num2 < 3 && squadMemberLookup.TryGetValue(key, out text))
                    {
                        num2++;
                        stringBuilder.Append('\n');
                        stringBuilder.Append(this.lang.Get("SQUAD_DONATED_TROOP_SENDER", new object[]
                        {
                            text,
                            value
                        }));
                    }
                    else
                    {
                        num += value;
                    }
                }
                if (num2 > 0 && num > 0)
                {
                    stringBuilder.Append('\n');
                    stringBuilder.Append(this.lang.Get("SQUAD_DONATED_TROOP_SENDER_OTHER", new object[]
                    {
                        num
                    }));
                }
            }
            return(stringBuilder.ToString());
        }
Пример #5
0
        protected void InitTroopGrid()
        {
            this.storageItemGrid = base.GetElement <UXGrid>("GridCurrentTroops");
            this.storageItemGrid.SetTemplateItem("CardCurrentTroops");
            this.storageItemGrid.Clear();
            this.troopList = new List <TroopUpgradeTag>();
            int        num        = 0;
            GamePlayer worldOwner = GameUtils.GetWorldOwner();
            List <SquadDonatedTroop> list;
            int squadStorageCapacity;

            if (this.isWarRequest)
            {
                SquadMemberWarData currentMemberWarData = Service.SquadController.WarManager.GetCurrentMemberWarData();
                list = currentMemberWarData.WarTroops;
                squadStorageCapacity = currentMemberWarData.BaseMap.GetSquadStorageCapacity();
            }
            else
            {
                list = SquadUtils.GetWorldOwnerSquadBuildingTroops();
                squadStorageCapacity = worldOwner.Map.GetSquadStorageCapacity();
            }
            int count = list.Count;

            if (count > 0)
            {
                StaticDataController staticDataController = Service.StaticDataController;
                for (int i = 0; i < count; i++)
                {
                    SquadDonatedTroop squadDonatedTroop = list[i];
                    TroopTypeVO       troopTypeVO       = staticDataController.Get <TroopTypeVO>(squadDonatedTroop.TroopUid);
                    int totalAmount = squadDonatedTroop.GetTotalAmount();
                    if (totalAmount > 0)
                    {
                        this.AddTroopItem(troopTypeVO, totalAmount);
                        num += totalAmount * troopTypeVO.Size;
                    }
                }
            }
            this.canRequestTroops = (num < squadStorageCapacity);
            this.UpdateScreenElementVisibility();
            this.storageItemGrid.RepositionItems();
        }