예제 #1
0
        public static List <RewardItem> CreateRewardListItems(IEnumerable <CommodityVO> commodities, RewardItem listItem)
        {
            List <RewardItem>  result     = new List <RewardItem>();
            List <CommodityVO> rewards    = TallyRewards(commodities);
            GossipModel        model      = AmbitionApp.GetModel <GossipModel>();
            RewardItem         item       = listItem;
            List <string>      duplicates = new List <string>();
            string             gossipName;
            GameObject         obj;
            bool           doCreate;
            CharacterModel characterModel = AmbitionApp.GetModel <CharacterModel>();
            CharacterVO    character;

            foreach (CommodityVO reward in rewards)
            {
                switch (reward.Type)
                {
                case CommodityType.Gossip:
                    gossipName = model.GetName(reward);
                    doCreate   = true;
                    break;

                case CommodityType.Favor:
                    character = characterModel.GetCharacter(reward.ID);
                    doCreate  = character != null &&
                                character.FavoredLocations?.Length + character.OpposedLocations?.Length > 0 &&
                                !duplicates.Contains(reward.ID);
                    if (!doCreate)
                    {
                        duplicates.Add(reward.ID);
                    }
                    break;

                case CommodityType.Livre:
                case CommodityType.Credibility:
                case CommodityType.Peril:
                    doCreate = true;
                    break;

                default:
                    doCreate = false;
                    break;
                }
                if (doCreate)
                {
                    if (item == null)
                    {
                        obj  = GameObject.Instantiate <GameObject>(listItem.gameObject, listItem.transform.parent);
                        item = obj.GetComponent <RewardItem>();
                    }
                    item.Data = reward;
                    item.gameObject.SetActive(true);
                    result.Add(item);
                    item = null;
                }
            }
            listItem.gameObject.SetActive(result.Count > 0);
            return(result);
        }
예제 #2
0
        // Adds new ranges or expands existing ones
        private List <RewardRange> Accumulate(List <RewardRange> ranges, List <RewardRange> rewards)
        {
            List <RewardRange> result = new List <RewardRange>(ranges);
            List <string>      gossip = new List <string>();
            GossipModel        model  = AmbitionApp.GetModel <GossipModel>();
            string             gossipName;
            RewardRange        range;
            CharacterVO        character;
            CommodityVO        commodity;

            foreach (RewardRange reward in rewards)
            {
                switch (reward.Type)
                {
                case CommodityType.Gossip:
                    commodity  = new CommodityVO(CommodityType.Gossip, reward.ID, reward.Low);
                    gossipName = model.GetName(commodity);
                    if (!gossip.Contains(gossipName))
                    {
                        gossip.Add(gossipName);
                        range = new RewardRange(ref commodity);
                        result.Add(range);
                    }
                    break;

                case CommodityType.Favor:
                    character = AmbitionApp.GetModel <CharacterModel>().GetCharacter(reward.ID);
                    if (character?.FavoredLocations?.Length + character?.OpposedLocations?.Length > 0)
                    {
                        UpdateOrAdd(ref result, reward.Type, reward.ID, reward.Low, reward.High);
                    }
                    break;

                case CommodityType.Livre:
                case CommodityType.Credibility:
                case CommodityType.Peril:
                case CommodityType.Servant:
                    UpdateOrAdd(ref result, reward.Type, reward.ID, reward.Low, reward.High, true);
                    break;
                }
            }
            return(result);
        }