コード例 #1
0
 /// <summary>
 /// default ctor, create default character
 /// </summary>
 public CharacterNPC()
 {
     this.hp      = 100;
     this.level   = 1;
     this.mana    = 50;
     this.power   = 20;
     this.defense = 20;
     this.side    = Side.neutral;
     this.type    = NPCType.beast;
     this.name    = "Default";
     this.priors  = new Priorities();
 }
コード例 #2
0
        /// <summary>
        /// from generated state-prob pairs choose the best one and returns new Confict state
        /// </summary>
        /// <param name="myself">npc, which is choosing from actions</param>
        /// <param name="enemy">enemy npc on which is the target</param>
        /// <param name="priors">priors from npc character, useless for now</param>
        /// <param name="actionType">type of action</param>
        /// <returns>new confict state</returns>
        public ConflictState GetNextAction(IActing myself, IActing enemy, Priorities priors, out Action selectedAction)
        {
            ConflictState currentState = new ConflictState(myself.GetStatus(), enemy.GetStatus());
            Priorities    priorities   = priors;
            CharacterNPC  myChar       = myself.GetCharacter();

            //if (this.stateSpace.Count == 0)
            //{
            //    CreateStateSpace(currentState, myChar);
            //}

            List <StateProbPairs> expanders = Expand(currentState, myChar);

            StateProbPairs result = new StateProbPairs();

            int lowestCost = int.MaxValue;
            int actionCost = int.MaxValue;

            foreach (StateProbPairs pairs in expanders)
            {
                //if (this.stateSpace.Contains(pairs))
                //{
                //    Logging.Logger.AddInfo(pairs.ToString() + " je obsazeno");
                //}
                actionCost = ComputeCost(currentState, pairs, myChar);

                if (actionCost < lowestCost && actionCost >= 0)
                {
                    result     = pairs;
                    lowestCost = actionCost;
                }
            }
            if (result.states == null)
            {
                result.states.Add(currentState);
                Action empty = new Action();
                empty.name    = "empty";
                empty.time    = 5000;
                result.action = empty;
                result.probabilities.Add(100);
            }

            int index = 0;

            if (result.probabilities.Count > 1)
            {
                int randChoose = rand.Next(100);
                if (randChoose < result.probabilities[0])
                {
                    index = 0;
                }
                else if (randChoose < result.probabilities[0] + result.probabilities[1])
                {
                    index = 1;
                }
                else
                {
                    if (result.states.Count > 2)
                    {
                        index = 2;
                    }
                }
            }

            if (index >= result.states.Count)
            {
                index = 0;
            }

            Logging.Logger.AddInfo(myChar.name + ": " + result.action.ToString() + " proti " + enemy.GetCharacter().name + ", cost=" + lowestCost + ", efekt: " + index);
            myself.SetCoolDown(result.action.time);

            selectedAction  = result.action;
            this.lastAction = selectedAction;
            //return result.states[index];
            return(result.states[0]);
        }
コード例 #3
0
        /// <summary>
        /// loads character from xml
        /// </summary>
        /// <param name="path">path to xml configuration</param>
        private void LoadFromFile(String path)
        {
            XmlDataDocument doc = new XmlDataDocument();

            doc.Load(path);

            foreach (XmlNode node in doc.GetElementsByTagName("NPC"))
            {
                foreach (XmlNode child in node.ChildNodes)
                {
                    switch (child.Name)
                    {
                    case "Name":
                        this.name = child.InnerText;
                        break;

                    case "Side":
                        this.side = (Side)Convert.ToInt32(child.InnerText);
                        break;

                    case "Type":
                        this.type = (NPCType)Convert.ToInt32(child.InnerText);
                        break;

                    case "VisualRange":
                        this.visualRange = Convert.ToInt32(child.InnerText);
                        break;

                    case "Attributes":
                        this.hp      = Convert.ToInt32(child.Attributes[hp].InnerText);
                        this.level   = Convert.ToInt32(child.Attributes["level"].InnerText);
                        this.mana    = Convert.ToInt32(child.Attributes["mana"].InnerText);
                        this.power   = Convert.ToInt32(child.Attributes["power"].InnerText);
                        this.defense = Convert.ToInt32(child.Attributes["defense"].InnerText);
                        break;

                    case "Priors":
                        Priorities priors = new Priorities();
                        priors.priorsList = new List <int>();
                        priors.killPrior  = Convert.ToInt32(child.Attributes["kill"].Value);
                        priors.priorsList.Add(priors.killPrior);
                        priors.livePrior = Convert.ToInt32(child.Attributes["live"].Value);
                        priors.priorsList.Add(priors.livePrior);
                        priors.hidePrior = Convert.ToInt32(child.Attributes["hide"].Value);
                        priors.priorsList.Add(priors.helpPrior);
                        priors.overviewPrior = Convert.ToInt32(child.Attributes["overview"].Value);
                        priors.priorsList.Add(priors.overviewPrior);
                        priors.surprisePrior = Convert.ToInt32(child.Attributes["surprise"].Value);
                        priors.priorsList.Add(priors.surprisePrior);
                        priors.boostPrior = Convert.ToInt32(child.Attributes["boost"].Value);
                        priors.priorsList.Add(priors.boostPrior);
                        priors.coverPrior = Convert.ToInt32(child.Attributes["cover"].Value);
                        priors.priorsList.Add(priors.coverPrior);
                        priors.helpPrior = Convert.ToInt32(child.Attributes["help"].Value);
                        priors.priorsList.Add(priors.helpPrior);
                        this.priors = priors;
                        break;
                    }
                }
            }
        }
コード例 #4
0
 public ConflictState GetNextAction(IActing myself, IActing enemy, Priorities priors, out Action selectedAction)
 {
     //TODO dodelat
     selectedAction = this.attackActions[0];
     return(new ConflictState(myself.GetStatus(), enemy.GetStatus()));
 }