示例#1
0
        public void Execute(CommodityVO reward)
        {
            ServantModel model = AmbitionApp.GetModel <ServantModel>();

            switch (reward.Value)
            {
            case -1:
                AmbitionApp.SendMessage(ServantMessages.FIRE_SERVANT, reward.ID);
                model.Servants.RemoveAll(s => s.ID == reward.ID);
                model.Broadcast();
                break;

            case 0:
                ServantVO servant = model.GetServant(reward.ID);
                if (servant?.IsHired ?? false)
                {
                    AmbitionApp.SendMessage(ServantMessages.FIRE_SERVANT, reward.ID);
                }
                else
                {
                    AmbitionApp.SendMessage(ServantMessages.INTRODUCE_SERVANT, reward.ID);
                }
                break;

            default:
                AmbitionApp.SendMessage(ServantMessages.HIRE_SERVANT, reward.ID);
                break;
            }
        }
示例#2
0
 public bool Introduce(ServantVO servant)
 {
     if (RemoveFromDictionary(Unknown, servant) && AddToDictionary(Applicants, servant))
     {
         servant.Status = ServantStatus.Introduced;
         AmbitionApp.SendMessage(ServantMessages.SERVANT_INTRODUCED, servant);
         return(true);
     }
     return(false);
 }
示例#3
0
        public void Execute(string servantID)
        {
            ServantModel model   = AmbitionApp.GetModel <ServantModel>();
            ServantVO    servant = model.GetServant(servantID);

            if (servant != null && servant.Status == ServantStatus.Hired)
            {
                servant.Status = ServantStatus.Introduced;
                model.Broadcast();
            }
        }
示例#4
0
        public void Execute(ServantType type)
        {
            ServantModel model   = AmbitionApp.GetModel <ServantModel>();
            ServantVO    servant = model.GetServant(type);

            if (servant != null)
            {
                servant.Status = ServantStatus.Introduced;
                model.Broadcast();
            }
        }
示例#5
0
 public bool Hire(ServantVO servant)
 {
     if (!Servants.ContainsKey(servant.Slot) && RemoveFromDictionary(Applicants, servant))
     {
         servant.Status         = ServantStatus.Hired;
         Servants[servant.Slot] = servant;
         AmbitionApp.SendMessage <ServantVO>(ServantMessages.SERVANT_HIRED, servant);
         return(true);
     }
     return(false);
 }
示例#6
0
        public void Execute(string servantID)
        {
            ServantModel model   = AmbitionApp.GetModel <ServantModel>();
            ServantVO    servant = model.LoadServant(servantID);

            if (servant != null && !servant.IsHired)
            {
                if (model.GetServant(servant.Type)?.ID != servant.ID)
                {
                    AmbitionApp.SendMessage(ServantMessages.FIRE_SERVANT, servant.Type);
                }
                servant.Status = ServantStatus.Hired;
                model.Broadcast();
            }
        }
示例#7
0
        public ServantVO LoadServant(string servantID)
        {
            ServantVO servant = GetServant(servantID);

            if (servant != null)
            {
                return(servant);
            }
            servant = Resources.Load <ServantConfig>(SERVANT_PATH + servantID)?.GetServant();
            if (servant != null)
            {
                Servants.Add(servant);
                Broadcast();
            }
            return(servant);
        }
示例#8
0
        public void Execute(CommodityVO reward)
        {
            ServantModel servants = AmbitionApp.GetModel <ServantModel>();
            ServantVO    servant  = null;

            if (!servants.Servants.ContainsKey(reward.ID) && servants.Applicants.ContainsKey(reward.ID))
            {
                servant = Util.RNG.TakeRandom(servants.Applicants[reward.ID].ToArray());
                servants.Hire(servant);
            }
            if (servant == null)
            {
                reward.Type = CommodityType.Gossip;
                AmbitionApp.Reward(reward);
            }
        }
示例#9
0
        public ServantVO GetServant()
        {
            ServantVO result = new ServantVO()
            {
                ID        = name,
                Type      = Type,
                Wage      = Wage,
                Status    = Status,
                Modifiers = new Dictionary <string, float>()
            };

            foreach (SerializableHash <string, float> mod in Modifiers)
            {
                result.Modifiers[mod.Key] = mod.Value;
            }
            return(result);
        }
示例#10
0
        public bool Introduce(string servantType)
        {
            List <ServantVO> servants;

            if (!Unknown.TryGetValue(servantType, out servants) || servants.Count == 0)
            {
                return(false);
            }
            ServantVO servant = Util.RNG.TakeRandom(servants.ToArray());

            if (AddToDictionary(Applicants, servant))
            {
                Unknown[servantType].Remove(servant);
                servant.Status = ServantStatus.Introduced;
                AmbitionApp.SendMessage(ServantMessages.SERVANT_INTRODUCED, servant);
                return(true);
            }
            return(false);
        }
示例#11
0
 public string GetServantDescription(ServantVO servant)
 {
     return(AmbitionApp.Localize(ServantConsts.SERVANT_DESCRIPTION_KEY + servant.ID));
 }
示例#12
0
 public string GetServantTitle(ServantVO servant)
 {
     return(AmbitionApp.Localize(ServantConsts.SERVANT_TITLE_KEY + servant.ID));
 }
示例#13
0
 public string GetServantName(ServantVO servant)
 {
     return(AmbitionApp.Localize(ServantConsts.SERVANT_LOC_KEY + servant.ID));
 }
示例#14
0
        private bool RemoveFromDictionary(Dictionary <string, List <ServantVO> > dictionary, ServantVO servant)
        {
            string slot   = servant.Slot;
            bool   result = dictionary.ContainsKey(slot) && dictionary[slot].Remove(servant);

            if (dictionary[slot].Count == 0)
            {
                dictionary.Remove(slot);
            }
            return(result);
        }
示例#15
0
 private bool AddToDictionary(Dictionary <string, List <ServantVO> > dictionary, ServantVO servant)
 {
     if (!dictionary.ContainsKey(servant.Slot))
     {
         dictionary[servant.Slot] = new List <ServantVO>();
     }
     else if (dictionary[servant.Slot].Contains(servant))
     {
         return(false);
     }
     dictionary[servant.Slot].Add(servant);
     return(true);
 }
示例#16
0
 public bool Fire(ServantVO servant)
 {
     return((Servants.ContainsKey(servant.Slot) &&
             Servants[servant.Slot] == servant) &&
            Fire(servant.Slot));
 }