Exemple #1
0
        private static ActionChosen AICombatActionMeleeOnly(EcsRegistrar rgs, long globalId, long attackerId, List <long> battlefieldEntityIds)
        {
            var action = new ActionChosen {
                Action = Vals.CombatAction.DoNothing, AgentId = attackerId
            };

            var naturalWeaponsMap = rgs.GetPartSingle <Parts.NaturalWeaponsMap>(globalId);

            var targetIdsToWeights = battlefieldEntityIds
                                     .Select(id => new { Id = id, Agent = rgs.GetPartSingleOrDefault <Parts.Agent>(id) })
                                     .Where(a => a.Id != attackerId && a.Agent != null && !Vals.CombatStatusTag.CombatTerminalStatuses.Intersect(a.Agent.CombatStatusTags).Any())
                                     .ToDictionary(a => a.Id, a => 0);

            var attackerFaction     = rgs.GetPartSingle <Parts.Faction>(attackerId);
            var factionInteractions = rgs.GetPartSingle <Parts.FactionInteractionSet>(globalId);

            //eventually we have to figure out how to weight faction relative to everything else.
            var possibleTargetIds = targetIdsToWeights.Keys.ToArray();

            foreach (var possibleTargetId in possibleTargetIds)
            {
                var targetFaction = rgs.GetPartSingle <Parts.Faction>(possibleTargetId);
                targetIdsToWeights[possibleTargetId] = factionInteractions.Interactions
                                                       .SingleOrDefault(i => i.SourceFaction == attackerFaction.CurrentPublicFaction && i.TargetFaction == targetFaction.CurrentPublicFaction)
                                                       ?.Disposition ?? 0;
            }

            var minWeight = targetIdsToWeights.Values.Any() ? targetIdsToWeights.Values.Min() : 0;

            if (minWeight < 0)
            {
                var targetId = targetIdsToWeights.First(kvp => kvp.Value == minWeight).Key;

                var attackerAnatomy = rgs.GetPartSingle <Parts.Anatomy>(attackerId);

                //MWCTODO++: yaaaah this is way too human centric.
                var weaponId = attackerAnatomy.SlotsEquipped.GetValueOrDefault(Vals.BodySlots.WieldHandRight, 0);
                if (weaponId == 0)
                {
                    weaponId = attackerAnatomy.SlotsEquipped.GetValueOrDefault(Vals.BodySlots.WieldHandLeft, 0);
                }

                if (weaponId == 0)
                {
                    var nwmap = naturalWeaponsMap.NaturalWeaponSets.GetValueOrDefault(attackerAnatomy.NaturalWeaponsCategory, null);

                    if (nwmap != null && nwmap.Keys.Any())
                    {
                        //MWCTODO: and this isn't great.
                        weaponId = nwmap.First().Value;
                    }
                }

                action.Action         = Vals.CombatAction.AttackWeaponMelee;
                action.TargetEntityId = targetId;
                action.WeaponEntityId = weaponId;
            }

            return(action);
        }
Exemple #2
0
 public void SpellAction(Attack spell)
 {
     spell.UpdateDescription();
     if (ActionChosen != null)
     {
         ActionChosen.Invoke(spell);
     }
 }
Exemple #3
0
 public void SlowButtonClicked()
 {
     menuState    = false;
     actionChosen = (ActionChosen)3;
     actionState  = true;
     //Should only be possible if action is avaliable
     unitAction = GetActionOfType(ActionType.Slow);
     ProcessTurn();
 }
Exemple #4
0
        public void AttackAction()
        {
            IAction action = new BasicSwordAttack(player, currentWeapon);

            if (ActionChosen != null)
            {
                ActionChosen.Invoke(action);
            }
        }
Exemple #5
0
        private static ActionChosen GetHeroAction(List <ConsoleKeyAndChoice> keysToChoices, List <ConsoleKeyToTarget> keysToMeleeTargets, List <ConsoleKeyToTarget> keysToRangedTargets)
        {
            var actionChosen = new ActionChosen();

            string category = SampleGame.Vals.CombatCategory.TopLevelAction;

            //there might be a series of choices before we're done. we'll successively fill in parts of actionChosen as we repeat.
            Console.WriteLine("Choose an action:");
            while (true)
            {
                List <IConsoleMap> possibleChoices2 = (category == SampleGame.Vals.CombatCategory.RangedTarget)
                    ? keysToRangedTargets.ToList <IConsoleMap>()
                    : (category == SampleGame.Vals.CombatCategory.MeleeTarget)
                        ? keysToMeleeTargets.ToList <IConsoleMap>()
                        : keysToChoices.Where(kc => kc.Choice.Category == category).ToList <IConsoleMap>();

                DisplayCurrentChoices(possibleChoices2);

                var response = GetChoiceFromConsoleKeymap(possibleChoices2);
                if (response.Cki.Key == ConsoleKey.Backspace)
                {
                    Console.WriteLine("restart");
                    Console.WriteLine("");
                    category = SampleGame.Vals.CombatCategory.TopLevelAction;

                    continue;
                }
                else if (category == SampleGame.Vals.CombatCategory.MeleeTarget || category == SampleGame.Vals.CombatCategory.RangedTarget)
                {
                    var targetSelection = (ConsoleKeyToTarget)response;

                    actionChosen.TargetEntityId = targetSelection.TargetId;

                    return(actionChosen);
                }
                else
                {
                    var choice = (ConsoleKeyAndChoice)response;

                    actionChosen.AgentId        = choice.Choice.AgentId;
                    actionChosen.Action         = choice.Choice.Action;
                    actionChosen.WeaponEntityId = choice.Choice.WeaponEntityId;
                    actionChosen.WeaponBodySlot = choice.Choice.WeaponBodySlot;

                    category = choice.Choice.NextCategory;

                    if (choice.Choice.NextCategory == null)
                    {
                        return(actionChosen);
                    }
                }
            }
        }
Exemple #6
0
        public void DefendAction()
        {
            IAction action;

            if (currentWeapon is IceShield)
            {
                action = new IceDefend(player, 1, currentWeapon);
            }
            else
            {
                action = new Defend(player, 1, currentWeapon);
            }
            if (ActionChosen != null)
            {
                ActionChosen.Invoke(action);
            }
        }
 // Update is called once per frame
 public override void Update()
 {
     base.Update();
     BackToNormalColorIfNeeded();
     if (ManageDeath())
     {
         return;
     }
     ;
     // decide what to do whene there is something to do, for example the target died.
     if (WhenToThinkAboutDecision < Time.time)
     {
         WhenToThinkAboutDecision = Time.time + UnityEngine.Random.Range(1, 1.8f);
         actionChosen             = ChooseAction();
     }
     //
     Act();
 }
Exemple #8
0
 //internal static List<Messages.Combat> ProcessAgentAction(EcsRegistrar rgs, long agentId, long? targetId, string action)
 internal static List <Messages.Combat> ProcessAgentAction(EcsRegistrar rgs, long agentId, ActionChosen agentAction)
 {
     if (Stances.Contains(agentAction.Action))
     {
         return(ApplyStance(rgs, agentId, agentAction.Action));
     }
     else if (agentAction.Action == Vals.CombatAction.SwitchToAI)
     {
         return(SwitchToAI(rgs, agentId));
     }
     else if (agentAction.Action == Vals.CombatAction.AttackWeaponMelee)
     {
         return(ResolveSingleTargetMelee(rgs, agentId, agentAction.WeaponEntityId.Value, agentAction.TargetEntityId.Value));
     }
     else if (agentAction.Action == Vals.CombatAction.DoNothing)
     {
         var agentNames = rgs.GetPartSingle <Parts.EntityName>(agentId);
         return(new List <Messages.Combat> {
             new Messages.Combat {
                 Tick = rgs.NewId(), ActorId = agentId, ActorAction = $"{agentNames.ProperName} stands still and looks around in confusion. Probably some programmer failed to give him a good action in this scenario."
             }
         });
     }
     else
     {
         throw new ArgumentException($"Action '{agentAction.Action}' not supported.");
     }
 }