コード例 #1
0
        public static Entity recreatePlayer(PlayerState playerHolder, Position position)
        {
            Entity e = ecs_instance.create();

            ecs_instance.add_component(e, position);
            //ECSInstance.entity_manager.add_component(e, new Position(new Vector2(0, 0), new Vector2(12.5f)));
            ecs_instance.add_component(e, new Velocity(4f));
            ecs_instance.add_component(e, new Controllable());
            //ECSInstance.entity_manager.add_component(e, new Sprite("characters\\lor_lar_sheet", "characters\\normals\\lor_lar_sheet_normals",32,32,0,0));
            ecs_instance.add_component(e, AnimationFactory.createPlayerAnimation());
            ecs_instance.add_component(e, new CameraFocus(75));
            ecs_instance.add_component(e, new MapCollidable());
            ecs_instance.add_component(e, new Heading());
            ecs_instance.add_component(e, createLight(true, 8, new Vector3(new Vector2(576f, 360f), 10), 0.5f, new Vector4(1, 1, .6f, 1)));
            ecs_instance.add_component(e, new Transform());

            /* LIKELY NOT NEEDED
             * GameSession.PlayerState.Attributes.setEntityId(e.Id);
             * GameSession.PlayerState.Factions.setEntityId(e.Id);
             * GameSession.PlayerState.Health.setEntityId(e.Id);
             * GameSession.PlayerState.Information.setEntityId(e.Id);
             * GameSession.PlayerState.Interactable.setEntityId(e.Id);
             * GameSession.PlayerState.Knowledges.setEntityId(e.Id);
             * GameSession.PlayerState.Life.setEntityId(e.Id);
             * GameSession.PlayerState.Skills.setEntityId(e.Id);
             */

            ecs_instance.add_component(e, playerHolder.Information);
            ecs_instance.add_component(e, playerHolder.Life);
            ecs_instance.add_component(e, playerHolder.Interactable);

            ItemFactory iFactory = new ItemFactory(ecs_instance);

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

            ecs_instance.add_component(e, playerHolder.Knowledges);
            ecs_instance.add_component(e, playerHolder.Statistics);
            ecs_instance.add_component(e, playerHolder.Health);
            ecs_instance.add_component(e, playerHolder.Skills);
            ecs_instance.add_component(e, playerHolder.Factions);

            ecs_instance.tag_manager.tag_entity("PLAYER", e);

            ecs_instance.resolve(e);

            return(e);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
0
        public static Entity createPlayer(int skillLevel)
        {
            Entity e = ecs_instance.create();

            GameMap gameMap = ComponentMapper.get <GameMap> (ecs_instance.tag_manager.get_entity_by_tag("MAP"));
            Vector2 pos     = MapFactory.findSafeLocation(gameMap);

            //ECSInstance.entity_manager.add_component(e, new Position(new Vector2(576f, 360f),new Vector2(12.5f)));
            ecs_instance.add_component(e, new Position(pos, new Vector2(16)));
            //ECSInstance.entity_manager.add_component(e, new Position(new Vector2(0, 0), new Vector2(12.5f)));
            ecs_instance.add_component(e, new Velocity(4f));
            ecs_instance.add_component(e, new Controllable());
            //ECSInstance.entity_manager.add_component(e, new Sprite("characters\\lor_lar_sheet", "characters\\normals\\lor_lar_sheet_normals",32,32,0,0));;

            ecs_instance.add_component(e, AnimationFactory.createPlayerAnimation());
            ecs_instance.add_component(e, new CameraFocus(75));
            ecs_instance.add_component(e, new MapCollidable());
            ecs_instance.add_component(e, new Heading());
            ecs_instance.add_component(e, createLight(true, 8, new Vector3(new Vector2(576f, 360f), 10), 0.5f, new Vector4(1, 1, .6f, 1)));
            ecs_instance.add_component(e, new Transform());

            Information info = new Information();

            info.GeneralGroup   = "HUMAN";
            info.VariationGroup = "NONE";
            info.UniqueGroup    = "NONE";
            info.Name           = "PLAYER";
            ecs_instance.add_component(e, info);

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

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

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

            interact.SupportedInteractions.PROJECTILE_COLLIDABLE = true;
            interact.SupportedInteractions.ATTACKABLE            = true;
            interact.SupportedInteractions.MAY_RECEIVE_VICTORY   = true;
            interact.SupportedInteractions.MAY_ADVANCE           = true;
            interact.SupportedInteractions.CAUSES_ADVANCEMENT    = false;
            interact.SupportedInteractions.AWARDS_VICTORY        = 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 * 5);            // new Health(5000);//

            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);

            Factions factions = new Factions();

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

            GameSession.PlayerState              = new PlayerState();
            GameSession.PlayerState.Statistics   = statistics;
            GameSession.PlayerState.Factions     = factions;
            GameSession.PlayerState.Health       = health;
            GameSession.PlayerState.Information  = info;
            GameSession.PlayerState.Interactable = interact;
            GameSession.PlayerState.Knowledges   = knowledges;
            GameSession.PlayerState.Life         = life;
            GameSession.PlayerState.Skills       = skills;

            ecs_instance.tag_manager.tag_entity("PLAYER", e);

            ecs_instance.resolve(e);

            return(e);
        }