Ejemplo n.º 1
0
        public override void Perform(MobUpdateContext context)
        {
            NavMesh navMesh= context.moveRequest.Room.runtime_nav_mesh;
            float max_range= 5.0f; // Compute max range from mob type
            uint[] navCells = navMesh.ComputeNavCellsInRadius(context.mob.Position, max_range, false);
            Random rng = context.mob.AIState.behavior_data.GetMobRandomNumberGenerator();
            RNGUtilities.DeterministicKnuthShuffle(rng, navCells);
            Point3d targetPosition = new Point3d(context.mob.Position);

            // Pick the first random nav cell in range that we have line of sight to
            foreach (uint navCellIndex in navCells)
            {
                Point3d testTarget = navMesh.ComputeNavCellCenter(navCellIndex);
                bool canSee = navMesh.PointCanSeeOtherPoint(context.mob.Position, testTarget);

                if (canSee)
                {
                    targetPosition = testTarget;
                    break;
                }
            }

            // Compute the side effect of actually moving the mob on the update context
            context.MoveMob(targetPosition);
            context.MobPostDialog("Soo bored...");
        }
Ejemplo n.º 2
0
        public override void Perform(MobUpdateContext context)
        {
            NavMesh navMesh   = context.moveRequest.Room.runtime_nav_mesh;
            float   max_range = 5.0f; // Compute max range from mob type

            uint[] navCells = navMesh.ComputeNavCellsInRadius(context.mob.Position, max_range, false);
            Random rng      = context.mob.AIState.behavior_data.GetMobRandomNumberGenerator();

            RNGUtilities.DeterministicKnuthShuffle(rng, navCells);
            Point3d targetPosition = new Point3d(context.mob.Position);

            // Pick the first random nav cell in range that we have line of sight to
            foreach (uint navCellIndex in navCells)
            {
                Point3d testTarget = navMesh.ComputeNavCellCenter(navCellIndex);
                bool    canSee     = navMesh.PointCanSeeOtherPoint(context.mob.Position, testTarget);

                if (canSee)
                {
                    targetPosition = testTarget;
                    break;
                }
            }

            // Compute the side effect of actually moving the mob on the update context
            context.MoveMob(targetPosition);
            context.MobPostDialog("Soo bored...");
        }
Ejemplo n.º 3
0
        public override bool CanActivate(MobUpdateContext context)
        {
            MobAIPerceptionState perception = context.mob.AIState.perception_data;
            EntityProp           prop       = perception.GetPlayerTargetProp();
            bool canActivate = (prop != null && prop.propStatus == EntityProp.ePropStatus.orphaned);

            return(canActivate);
        }
Ejemplo n.º 4
0
        public override bool CanActivate(MobUpdateContext context)
        {
            EntityProp energyTankProp = context.mob.AIState.perception_data.GetEnergyTankTargetProp();

            return
                (energyTankProp != null &&
                 energyTankProp.propStatus >= EntityProp.ePropStatus.assumed &&
                 energyTankProp.faction != GameConstants.eFaction.ai &&
                 energyTankProp.energy > 0);
        }
Ejemplo n.º 5
0
        public void Update(
            MobUpdateContext context)
        {
            // Get the current behavior running, if any
            MobAIBehaviorState behaviorState = context.mob.AIState.behavior_data;

            behaviorState.active_behavior_stack = "";
            ActivateBehaviors(context, m_root);

            //currentBehavior.GetType().Name;
        }
Ejemplo n.º 6
0
        public void Update(
            MobUpdateContext context)
        {
            // Get the current behavior running, if any
            MobAIBehaviorState behaviorState = context.mob.AIState.behavior_data;

            behaviorState.active_behavior_stack = "";
            ActivateBehaviors(context, m_root);

            //currentBehavior.GetType().Name;
        }
Ejemplo n.º 7
0
        public override void Perform(MobUpdateContext context)
        {
            MobAIPerceptionState perception = context.mob.AIState.perception_data;
            EntityProp           prop       = perception.GetPlayerTargetProp();

            if (prop.distance >= WorldConstants.ROOM_TILE_SIZE)
            {
                context.MobPostDialog("I though I saw someone over here");
                context.MoveMob(prop.GetPosition());
            }
        }
Ejemplo n.º 8
0
        public override bool CanActivate(MobUpdateContext context)
        {
            EntityProp energyTankProp = context.mob.AIState.perception_data.GetEnergyTankTargetProp();

            return
                (energyTankProp != null &&
                 context.mob.MobType.Abilities.energy_tank_drain_per_turn > 0 &&
                 // Even if we can't use the energy, we can deny the player from having it
                 //energyTankProp.energy < context.mob.MobType.MaxEnergy &&
                 energyTankProp.propStatus >= EntityProp.ePropStatus.assumed &&
                 energyTankProp.faction == GameConstants.eFaction.ai &&
                 energyTankProp.energy > 0);
        }
Ejemplo n.º 9
0
        public override bool CanActivate(MobUpdateContext context)
        {
            EntityProp energyTankProp = context.mob.AIState.perception_data.GetEnergyTankTargetProp();

            return
                energyTankProp != null &&
                context.mob.MobType.Abilities.energy_tank_drain_per_turn > 0 &&
                // Even if we can't use the energy, we can deny the player from having it
                //energyTankProp.energy < context.mob.MobType.MaxEnergy &&
                energyTankProp.propStatus >= EntityProp.ePropStatus.assumed &&
                energyTankProp.faction == GameConstants.eFaction.ai &&
                energyTankProp.energy > 0;
        }
Ejemplo n.º 10
0
        public override void Perform(MobUpdateContext context)
        {
            EntityProp energyTankProp = context.mob.AIState.perception_data.GetEnergyTankTargetProp();
            EnergyTank energyTank     = context.moveRequest.EnergyTanks.Find(e => e.ID == energyTankProp.target_object_id);

            if (energyTank.Faction == GameConstants.eFaction.ai)
            {
                // We can only drain up to what we can take and whats left in the energy tank
                int drainAmount =
                    Math.Min(energyTank.Energy, context.mob.MobType.Abilities.energy_tank_drain_per_turn);

                context.MobDrainEnergyTank(energyTank, drainAmount);
                context.MobPostDialog("Sweet Sweet Energy...");
            }
            else
            {
                context.MoveMob(energyTank.Position);
                context.MobPostDialog("What?! Someone hacked this! Grrr...");
            }

            // Update the energy on the prop
            energyTankProp.energy = energyTank.Energy;
        }
Ejemplo n.º 11
0
        private bool ActivateBehaviors(
            MobUpdateContext context,
            MobBehavior behavior)
        {
            bool foundBehaviorToActivate = false;

            // Can the behavior be activated
            if (behavior.CanActivate(context))
            {
                foundBehaviorToActivate = true;

                // Perform the behavior we can activate
                behavior.Perform(context);

                // Add the behavior to the list of behaviors that was activated
                if (context.mob.AIState.behavior_data.active_behavior_stack.Length > 0)
                {
                    context.mob.AIState.behavior_data.active_behavior_stack += ".";
                }
                context.mob.AIState.behavior_data.active_behavior_stack += behavior.GetType().Name;

                // Try to activate children behaviors
                if (behavior.Children != null)
                {
                    foreach (MobBehavior childBehavior in behavior.Children)
                    {
                        // Stop searching if this child behavior could be activated
                        if (ActivateBehaviors(context, childBehavior))
                        {
                            break;
                        }
                    }
                }
            }

            return(foundBehaviorToActivate);
        }
Ejemplo n.º 12
0
        public override void Perform(MobUpdateContext context)
        {
            EntityProp energyTankProp = context.mob.AIState.perception_data.GetEnergyTankTargetProp();
            EnergyTank energyTank     = context.moveRequest.EnergyTanks.Find(e => e.ID == energyTankProp.target_object_id);

            if (energyTank.Faction == GameConstants.eFaction.player)
            {
                context.MobHackEnergyTank(energyTank);
                context.MobPostDialog("Which team owns one less energy tank? Team Player!");
            }
            else if (energyTank.Faction == GameConstants.eFaction.neutral)
            {
                context.MobHackEnergyTank(energyTank);
                context.MobPostDialog("Energy Tank claimed for the AI Team!");
            }
            else if (energyTank.Faction == GameConstants.eFaction.ai)
            {
                context.MobHackEnergyTank(energyTank);
                context.MobPostDialog("Oh! I guess we already owned this energy tank");
            }

            // Update the faction on the prop
            energyTankProp.faction = energyTank.Faction;
        }
Ejemplo n.º 13
0
 public override bool CanActivate(MobUpdateContext context)
 {
     return(false);
 }
Ejemplo n.º 14
0
 public override bool CanActivate(MobUpdateContext context)
 {
     return false;
 }
Ejemplo n.º 15
0
 public virtual bool CanActivate(MobUpdateContext context)
 {
     return true;
 }
Ejemplo n.º 16
0
 public virtual void Perform(MobUpdateContext context)
 {
     // Nothing to do
 }
Ejemplo n.º 17
0
 public void Update(
     MobUpdateContext context)
 {
     MobBehaviorTree.GetInstance().Update(context);
 }
Ejemplo n.º 18
0
 public virtual bool CanActivate(MobUpdateContext context)
 {
     return(true);
 }
Ejemplo n.º 19
0
 public virtual void Perform(MobUpdateContext context)
 {
     // Nothing to do
 }
Ejemplo n.º 20
0
        public override void Perform(MobUpdateContext context)
        {
            EntityProp energyTankProp = context.mob.AIState.perception_data.GetEnergyTankTargetProp();
            EnergyTank energyTank = context.moveRequest.EnergyTanks.Find(e => e.ID == energyTankProp.target_object_id);

            if (energyTank.Faction == GameConstants.eFaction.ai)
            {
                // We can only drain up to what we can take and whats left in the energy tank
                int drainAmount =
                    Math.Min(energyTank.Energy, context.mob.MobType.Abilities.energy_tank_drain_per_turn);

                context.MobDrainEnergyTank(energyTank, drainAmount);
                context.MobPostDialog("Sweet Sweet Energy...");
            }
            else
            {
                context.MoveMob(energyTank.Position);
                context.MobPostDialog("What?! Someone hacked this! Grrr...");
            }

            // Update the energy on the prop
            energyTankProp.energy = energyTank.Energy;
        }
Ejemplo n.º 21
0
 public void Update(
     MobUpdateContext context)
 {
     MobBehaviorTree.GetInstance().Update(context);
 }
Ejemplo n.º 22
0
        private bool ActivateBehaviors(
            MobUpdateContext context,
            MobBehavior behavior)
        {
            bool foundBehaviorToActivate = false;

            // Can the behavior be activated
            if (behavior.CanActivate(context))
            {
                foundBehaviorToActivate = true;

                // Perform the behavior we can activate
                behavior.Perform(context);

                // Add the behavior to the list of behaviors that was activated
                if (context.mob.AIState.behavior_data.active_behavior_stack.Length > 0)
                {
                    context.mob.AIState.behavior_data.active_behavior_stack += ".";
                }
                context.mob.AIState.behavior_data.active_behavior_stack += behavior.GetType().Name;

                // Try to activate children behaviors
                if (behavior.Children != null)
                {
                    foreach (MobBehavior childBehavior in behavior.Children)
                    {
                        // Stop searching if this child behavior could be activated
                        if (ActivateBehaviors(context, childBehavior))
                        {
                            break;
                        }
                    }
                }
            }

            return foundBehaviorToActivate;
        }
Ejemplo n.º 23
0
        public override void Perform(MobUpdateContext context)
        {
            EntityProp energyTankProp = context.mob.AIState.perception_data.GetEnergyTankTargetProp();
            EnergyTank energyTank = context.moveRequest.EnergyTanks.Find(e => e.ID == energyTankProp.target_object_id);

            if (energyTank.Faction == GameConstants.eFaction.player)
            {
                context.MobHackEnergyTank(energyTank);
                context.MobPostDialog("Which team owns one less energy tank? Team Player!");
            }
            else if (energyTank.Faction == GameConstants.eFaction.neutral)
            {
                context.MobHackEnergyTank(energyTank);
                context.MobPostDialog("Energy Tank claimed for the AI Team!");
            }
            else if (energyTank.Faction == GameConstants.eFaction.ai)
            {
                context.MobHackEnergyTank(energyTank);
                context.MobPostDialog("Oh! I guess we already owned this energy tank");
            }

            // Update the faction on the prop
            energyTankProp.faction = energyTank.Faction;
        }
Ejemplo n.º 24
0
        public override bool CanActivate(MobUpdateContext context)
        {
            EntityProp energyTankProp= context.mob.AIState.perception_data.GetEnergyTankTargetProp();

            return
                energyTankProp != null &&
                energyTankProp.propStatus >= EntityProp.ePropStatus.assumed &&
                energyTankProp.faction != GameConstants.eFaction.ai &&
                energyTankProp.energy > 0;
        }