示例#1
0
        protected override void process(Entity entity)
        {
            Health health = (Health)h_HealthMapper.get(entity);

            if (health.CurrentHealth <= 0)
            {
                Life life = (Life)h_LifeMapper.get(entity);

                if (life.IsAlive)
                {
                    UtilFactory.createSound("audio\\effects\\death", true, 1f);

                    //issue victory
                    Aggrivation aggro = (Aggrivation)h_AggroMapper.get(entity);

                    if (aggro != null)
                    {
                        foreach (Entity receiver in aggro.HateList)
                        {
                            Interactable interactor = (Interactable)h_InteractionMapper.get(entity);
                            Interactable interactee = (Interactable)h_InteractionMapper.get(receiver);

                            if (interactor == null || interactee == null)
                            {
                                continue;
                            }

                            if (interactor.SupportedInteractions.AWARDS_VICTORY &&
                                interactee.SupportedInteractions.MAY_RECEIVE_VICTORY)
                            {
                                UtilFactory.createVictoryAward(entity, receiver, GameConfig.AwardDefs.VictoryMinimum);
                            }
                        }
                    }
                }

                life.IsAlive = false;


                return;
            }

            health.TimeSinceLastRecover += ecs_instance.ElapsedTime;

            if (health.TimeSinceLastRecover > health.RecoveryRate)
            {
                health.TimeSinceLastRecover = 0;

                health.CurrentHealth += health.RecoveryAmmount;

                if (health.CurrentHealth > health.MaxHealth)
                {
                    health.CurrentHealth = health.MaxHealth;
                }
            }
        }
示例#2
0
        private static void doDamageAction(ActionPackage aPack)
        {
            Aggrivation aggro = ComponentMapper.get <Aggrivation> (aPack.Target);

            //check aggro and add if not present
            if (aggro != null)
            {
                if (!aggro.HateList.Contains(aPack.Owner))
                {
                    aggro.HateList.Add(aPack.Owner);
                }
            }

            switch (aPack.ActionDef.DamageDef.DamageBasis)
            {
            case DamageBasis.ATTRIBUTE:
                break;

            case DamageBasis.ITEM:
                break;

            case DamageBasis.NONE:
                break;

            case DamageBasis.SKILL:
                break;

            case DamageBasis.STATIC:
                doStaticDamage(aPack);
                break;

            case DamageBasis.WEAPON:
                doWeaponDamage(aPack);
                break;

            default:
                return;
            }
        }
示例#3
0
        protected override void process(Entity entity)
        {
            //retrieve this attack
            _CurrentEntity = entity;
            Attack attack = (Attack)_AttackMapper.get(entity);

            //see if defender is aggroable
            Aggrivation aggro = (Aggrivation)_AggroMapper.get(attack.Defender);

            if (aggro != null)
            {
                //set aggro
                if (!aggro.HateList.Contains(attack.Attacker))
                {
                    aggro.HateList.Add(attack.Attacker);
                }
            }


            //determine type of attack and handle it
            switch (attack.AttackType)
            {
            case AttackType.Melee:
                handleMelee(attack);
                break;

            case AttackType.Projectile:
                handleProjectile(attack);
                break;

            case AttackType.Ability:
                handleAbility(attack);
                break;

            default:
                ecs_instance.delete_entity(entity);
                break;
            }
        }
示例#4
0
        public Entity createCharacter(CharacterDef characterDef, Vector2 position)
        {
            Entity e = ecs_instance.create();

            ecs_instance.add_component(e, new Position(position, new Vector2(16)));
            ecs_instance.add_component(e, new Velocity(3f));
            ecs_instance.add_component(e, new AiBehavior(new WanderingEnemyBehavior(e, ecs_instance)));
            ecs_instance.add_component(e, new MapCollidable());
            ecs_instance.add_component(e, new Heading());
            ecs_instance.add_component(e, new Transform());
            ecs_instance.add_component(e, new Aggrivation());


            //create avatar
            ecs_instance.add_component(e, AnimationFactory.createAvatar(characterDef.AvatarDef.Name));

            //create info
            Information info = new Information();

            info.Name           = characterDef.InfoDef.Name;
            info.GeneralGroup   = characterDef.InfoDef.GeneralGroup;
            info.VariationGroup = characterDef.InfoDef.VariationGroup;
            info.UniqueGroup    = characterDef.InfoDef.UniqueGroup;
            ecs_instance.add_component(e, info);

            //create life
            Life life = new Life();

            life.IsAlive        = true;
            life.DeathLongevity = characterDef.LifeDef.DeathLongevity;
            ecs_instance.add_component(e, life);

            //create interactions
            Interactable interact = new Interactable();

            interact.SupportedInteractions = characterDef.SupportedInteractions;
            ecs_instance.add_component(e, interact);

            //create test equipment
            //FIXME:
            ItemFactory iFactory = new ItemFactory(ecs_instance);

            ecs_instance.add_component(e, iFactory.createTestEquipment());

            //setup knowledges
            Knowledges knowledges = new Knowledges();

            foreach (Knowledge knowledge in characterDef.KnowledgesDef.GeneralKnowledges)
            {
                Knowledge k = knowledge;
                k.Value = characterDef.SkillLevel;
                knowledges.GeneralKnowledge.Add(knowledge.Name, k);
            }

            foreach (Knowledge knowledge in characterDef.KnowledgesDef.VariationKnowledges)
            {
                knowledges.VariationKnowledge.Add(knowledge.Name, knowledge);
            }

            foreach (Knowledge knowledge in characterDef.KnowledgesDef.UniqueKnowledges)
            {
                knowledges.UniqueKnowledge.Add(knowledge.Name, knowledge);
            }
            ecs_instance.add_component(e, knowledges);

            //setup attributes
            Statistics statistics = new Statistics();

            statistics.Endurance         = characterDef.StatisticsDef.Endurance;
            statistics.Endurance.Value   = characterDef.SkillLevel;
            statistics.Focus             = characterDef.StatisticsDef.Focus;
            statistics.Focus.Value       = characterDef.SkillLevel;
            statistics.Mind              = characterDef.StatisticsDef.Mind;
            statistics.Mind.Value        = characterDef.SkillLevel;
            statistics.Muscle            = characterDef.StatisticsDef.Muscle;
            statistics.Muscle.Value      = characterDef.SkillLevel;
            statistics.Perception        = characterDef.StatisticsDef.Perception;
            statistics.Perception.Value  = characterDef.SkillLevel;
            statistics.Personality       = characterDef.StatisticsDef.Personality;
            statistics.Personality.Value = characterDef.SkillLevel;
            statistics.Quickness         = characterDef.StatisticsDef.Quickness;
            statistics.Quickness.Value   = characterDef.SkillLevel;
            ecs_instance.add_component(e, statistics);

            //create health
            Health health = new Health(statistics.Endurance.Value * 3);

            health.RecoveryAmmount = statistics.Endurance.Value / 5;
            health.RecoveryRate    = 1000;
            ecs_instance.add_component(e, health);

            //setup skills
            Skills skills = new Skills();

            skills.Avoidance       = characterDef.SkillsDef.Avoidance;
            skills.Melee           = characterDef.SkillsDef.Melee;
            skills.Ranged          = characterDef.SkillsDef.Ranged;
            skills.Ranged.Value    = characterDef.SkillLevel;
            skills.Avoidance.Value = characterDef.SkillLevel;
            skills.Melee.Value     = characterDef.SkillLevel;
            ecs_instance.add_component(e, skills);

            //setup factions
            Factions factions = new Factions();

            factions.OwnerFaction = characterDef.FactionsDef.OwnerFaction;
            foreach (Faction faction in characterDef.FactionsDef.Factions)
            {
                factions.KnownFactions.Add(faction.Name, faction);
            }
            ecs_instance.add_component(e, factions);

            Aggrivation aggro = new Aggrivation();

            ecs_instance.add_component(e, aggro);

            ecs_instance.add_component(e, EntityFactory.createLight(true, 3, new Vector3(position, 10), 0.5f, new Vector4(1, 1, .6f, 1)));

            ecs_instance.group_manager.add_entity_to_group("WANDERERS", e);

            ecs_instance.resolve(e);

            return(e);
        }
示例#5
0
        public void createBatEnemy(Vector2 position, int skillLevel)
        {
            Entity e = ecs_instance.create();

            ecs_instance.add_component(e, new Position(position, new Vector2(16)));
            ecs_instance.add_component(e, new Velocity(3f));
            ecs_instance.add_component(e, new AiBehavior(new WanderingEnemyBehavior(e, ecs_instance)));
            ecs_instance.add_component(e, new MapCollidable());
            ecs_instance.add_component(e, new Heading());
            ecs_instance.add_component(e, new Transform());
            ecs_instance.add_component(e, new Aggrivation());
            ecs_instance.add_component(e, AnimationFactory.createAvatar("BAT"));

            //create info
            Information info = new Information();

            info.Name           = "TEST WANDERER";
            info.GeneralGroup   = "BAT";
            info.VariationGroup = "NONE";
            info.UniqueGroup    = "NONE";
            ecs_instance.add_component(e, info);

            //create life
            Life life = new Life();

            life.IsAlive        = true;
            life.DeathLongevity = 500;
            ecs_instance.add_component(e, life);

            //create interactions
            Interactable interact = new Interactable();

            interact.SupportedInteractions.PROJECTILE_COLLIDABLE = true;
            interact.SupportedInteractions.ATTACKABLE            = true;
            interact.SupportedInteractions.MELEE_ACTIONABLE      = true;
            interact.SupportedInteractions.AWARDS_VICTORY        = true;
            interact.SupportedInteractions.CAUSES_ADVANCEMENT    = true;
            interact.SupportedInteractions.MAY_ADVANCE           = false;
            ecs_instance.add_component(e, interact);

            //create test equipment
            ItemFactory iFactory = new ItemFactory(ecs_instance);

            ecs_instance.add_component(e, iFactory.createTestEquipment());

            //setup experiences
            Knowledges knowledges = new Knowledges();

            knowledges.GeneralKnowledge.Add("HUMAN", new Knowledge {
                Name = "", Value = skillLevel, KnowledgeType = KnowledgeType.General
            });
            knowledges.GeneralKnowledge.Add("BAT", new Knowledge {
                Name = "", Value = skillLevel, KnowledgeType = KnowledgeType.General
            });
            knowledges.VariationKnowledge.Add("NONE", new Knowledge {
                Name = "", Value = 0f, KnowledgeType = KnowledgeType.General
            });
            knowledges.UniqueKnowledge.Add("NONE", new Knowledge {
                Name = "", Value = 0f, KnowledgeType = KnowledgeType.General
            });
            ecs_instance.add_component(e, knowledges);

            //setup attributes
            Statistics statistics = new Statistics();

            statistics.Focus = new Statistic {
                Name = "FOCUS", Value = skillLevel, StatType = StatType.FOCUS
            };
            statistics.Endurance = new Statistic {
                Name = "ENDURANCE", Value = skillLevel, StatType = StatType.ENDURANCE
            };
            statistics.Mind = new Statistic {
                Name = "MIND", Value = skillLevel, StatType = StatType.MIND
            };
            statistics.Muscle = new Statistic {
                Name = "MUSCLE", Value = skillLevel, StatType = StatType.MUSCLE
            };
            statistics.Perception = new Statistic {
                Name = "PERCEPTION", Value = skillLevel, StatType = StatType.PERCEPTION
            };
            statistics.Personality = new Statistic {
                Name = "PERSONALITY", Value = skillLevel, StatType = StatType.PERSONALITY
            };
            statistics.Quickness = new Statistic {
                Name = "QUICKNESS", Value = skillLevel, StatType = StatType.QUICKNESS
            };
            ecs_instance.add_component(e, statistics);

            //create health
            Health health = new Health(statistics.Endurance.Value * 3);

            health.RecoveryAmmount = statistics.Endurance.Value / 5;
            health.RecoveryRate    = 1000;
            ecs_instance.add_component(e, health);

            //setup skills
            Skills skills = new Skills();

            skills.Ranged = new Skill {
                Name = "RANGED", Value = skillLevel, SkillType = SkillType.Offensive
            };
            skills.Avoidance = new Skill {
                Name = "AVOIDANCE", Value = skillLevel, SkillType = SkillType.Defensive
            };
            skills.Melee = new Skill {
                Name = "MELEE", Value = skillLevel, SkillType = SkillType.Offensive
            };
            ecs_instance.add_component(e, skills);

            //setup factions
            Factions factions = new Factions();

            factions.OwnerFaction = new Faction {
                Name = "WILDERNESS", Value = 100, FactionType = FactionType.Wilderness
            };
            factions.KnownFactions.Add("PLAYER", new Faction {
                Name = "PLAYER", Value = -10, FactionType = FactionType.Player
            });
            factions.KnownFactions.Add("ALLY", new Faction {
                Name = "ALLY", Value = -10, FactionType = FactionType.Ally
            });
            ecs_instance.add_component(e, factions);

            Aggrivation aggro = new Aggrivation();

            ecs_instance.add_component(e, aggro);

            ecs_instance.add_component(e, EntityFactory.createLight(true, 3, new Vector3(position, 10), 0.5f, new Vector4(1, 1, .6f, 1)));

            ecs_instance.group_manager.add_entity_to_group("WANDERERS", e);

            ecs_instance.resolve(e);
        }
        /// <summary>
        /// checks for nearby enemy factions
        /// </summary>
        /// <returns>true if hostile was detected</returns>
        private bool hasDetectedHostile()
        {
            if (w_LastNode == null)
            {
                return(false);
            }

            SpatialPartition spatial  = (SpatialPartition)w_SpatialMapper.get(w_Spatial);
            Position         position = (Position)w_PositionMapper.get(w_ThisEntity);
            List <Entity>    locals   = spatial.QuadTree.findAllWithinRange(position.Pos, 100f);


            //nothing to detect
            if (locals.Count == 0)
            {
                return(false);
            }

            for (int i = 0; i < locals.Count; i++)
            {
                //dont look at yourself
                if (locals[i] == w_ThisEntity)
                {
                    continue;
                }

                Factions factions = (Factions)w_FactionMapper.get(locals[i]);

                if (factions == null)
                {
                    continue;
                }

                //is this local known to this entity
                if (factions.KnownFactions.ContainsKey(w_EntityFaction.OwnerFaction.Name))
                {
                    //should this entity be hostile towards this local?
                    if (factions.KnownFactions[w_EntityFaction.OwnerFaction.Name].Value < 0)
                    {
                        Position pos  = (Position)w_PositionMapper.get(w_ThisEntity);
                        Position tPos = (Position)w_PositionMapper.get(locals[i]);

                        if (Vector2.Distance(pos.Pos + pos.Offset, tPos.Pos + tPos.Offset) <= 200f)
                        {
                            //go hostile against it
                            w_Target = locals[i];

                            Aggrivation aggro = (Aggrivation)w_AggroMapper.get(w_ThisEntity);
                            aggro.Target = w_Target;

                            return(true);
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }

            return(false);
        }