void SpawnOneObject() { Vector2FP random_position = new Vector2FP(); if (!RandomPosition(ref random_position)) { return; } Player player = GetOwnerPlayer(); LogicWorld logic_world = GetLogicWorld(); EntityManager entity_manager = logic_world.GetEntityManager(); IConfigProvider config = logic_world.GetConfigProvider(); BirthPositionInfo birth_info = new BirthPositionInfo(random_position.x, new FixPoint(0), random_position.z, new FixPoint(90)); ObjectCreationContext object_context = new ObjectCreationContext(); object_context.m_object_proxy_id = player.ProxyID; object_context.m_object_type_id = m_object_type_id; object_context.m_object_proto_id = m_object_proto_id; object_context.m_birth_info = birth_info; object_context.m_type_data = config.GetObjectTypeData(object_context.m_object_type_id); object_context.m_proto_data = config.GetObjectProtoData(object_context.m_object_proto_id); object_context.m_logic_world = logic_world; object_context.m_owner_id = ParentObject.ID; object_context.m_is_ai = true; object_context.m_is_local = player.IsLocal; Entity obj = entity_manager.CreateObject(object_context); m_current_objects[obj.ID] = random_position; obj.AddListener(SignalType.Die, m_listener_context); }
void InitializeComponents(ObjectCreationContext context) { List <ComponentData> components_data = context.m_type_data.m_components_data; for (int i = 0; i < components_data.Count; ++i) { AddComponent(components_data[i]); } if (context.m_proto_data != null) { var attributes = context.m_proto_data.m_attributes; if (attributes != null && attributes.Count > 0) { AttributeManagerComponent cmp = GetComponent(AttributeManagerComponent.ID) as AttributeManagerComponent; if (cmp != null) { var enumerator = attributes.GetEnumerator(); while (enumerator.MoveNext()) { cmp.SetAttributeBaseValue(enumerator.Current.Key, enumerator.Current.Value); } } } var skills = context.m_proto_data.m_skills; if (skills != null && skills.Count > 0) { SkillManagerComponent cmp = GetComponent(SkillManagerComponent.ID) as SkillManagerComponent; if (cmp != null) { var enumerator = skills.GetEnumerator(); while (enumerator.MoveNext()) { cmp.AddSkill(enumerator.Current.Key, enumerator.Current.Value); } } } } for (int i = 0; i < components_data.Count; ++i) { Component component = GetComponent(components_data[i].m_component_type_id); if (component == null) { continue; } component.InitializeComponent(); } for (int i = 0; i < components_data.Count; ++i) { Component component = GetComponent(components_data[i].m_component_type_id); if (component == null) { continue; } component.OnObjectCreated(); } }
public void InitializeObject(ObjectCreationContext context) { m_context = context; PreInitializeObject(context); InitializeComponents(context); PostInitializeObject(context); }
Skill CreateSkill(int skill_index, int skill_cfgid) { LogicWorld logic_world = GetLogicWorld(); SkillManager skill_manager = logic_world.GetSkillManager(); IConfigProvider config = logic_world.GetConfigProvider(); ObjectTypeData skill_data = config.GetSkillData(skill_cfgid); if (skill_data == null) { m_index2id[skill_index] = -1; return(null); } ObjectCreationContext object_context = new ObjectCreationContext(); object_context.m_object_type_id = skill_cfgid; object_context.m_type_data = skill_data; object_context.m_logic_world = logic_world; object_context.m_owner_id = ParentObject.ID; Skill skill = skill_manager.CreateObject(object_context); m_index2id[skill_index] = skill.ID; if (skill_index == DEFAULT_SKILL_INDEX) { m_default_skill_id = skill.ID; } if (skill.GetDefinitionComponent().StartsActive) { skill.Activate(GetCurrentTime()); } return(skill); }
public Entity CreateEntity(ObjectCreationContext context) { IConfigProvider config = m_outside_world.GetConfigProvider(); context.m_logic_world = this; context.m_type_data = config.GetObjectTypeData(context.m_object_type_id); context.m_proto_data = config.GetObjectProtoData(context.m_object_proto_id); return(m_entity_manager.CreateObject(context)); }
protected override void PreInitializeObject(ObjectCreationContext context) { Entity owner_entity = context.m_logic_world.GetEntityManager().GetObject(m_context.m_owner_id); if (owner_entity != null) { m_owner_component = owner_entity.GetComponent(SkillManagerComponent.ID) as SkillManagerComponent; m_mana_component = owner_entity.GetComponent(ManaComponent.ID) as ManaComponent; } }
protected override void PreInitializeObject(ObjectCreationContext context) { #if ENTITY_RENDER_MESSAGE if (context.m_logic_world.CanGenerateRenderMessage()) { m_render_messages = new List <RenderMessage>(); } #endif PlayerManager player_manager = context.m_logic_world.GetPlayerManager(); int player_id = player_manager.Proxyid2Objectid(context.m_object_proxy_id); context.m_owner_id = player_id; m_owner_player = player_manager.GetObject(player_id); }
protected override Player CreateObjectInstance(ObjectCreationContext context) { int object_id = context.m_object_id; int proxy_id = context.m_object_proxy_id; m_objectid2proxyid[object_id] = proxy_id; m_proxyid2objectid[proxy_id] = object_id; if (context.m_is_local) { m_local_player_id = object_id; } if (proxy_id == AI_ENEMY_PLAYER_PROXYID) { m_ai_enemy_player_id = object_id; } return(new Player()); }
protected override void AfterObjectCreated(RenderEntity entity) { ObjectCreationContext context = entity.GetCreationContext(); if (!context.m_is_local || context.m_is_ai) { return; } if (entity.GetLogicEntity().GetComponent(LocomotorComponent.ID) != null) { Component component = entity.AddComponent(PredictLogicComponent.ID); if (component != null) { component.InitializeComponent(); component.OnObjectCreated(); } } }
public TObject CreateObject(ObjectCreationContext context) { if (context.m_object_id < 0) { int id = m_id_generator.GenID(); context.m_object_id = id; } TObject obj = CreateObjectInstance(context); context.m_creation_time = m_logic_world.GetCurrentTime(); m_objects[context.m_object_id] = obj; if (context.m_name != null && context.m_name.Length > 0) { m_named_objects[context.m_name] = obj; } obj.InitializeObject(context); AfterObjectCreated(obj); m_is_dirty = true; return(obj); }
Effect CreateEffect(int target_entity_id) { LogicWorld logic_world = m_generator.GetLogicWorld(); EffectManager effect_manager = logic_world.GetEffectManager(); IConfigProvider config = logic_world.GetConfigProvider(); ObjectTypeData effect_data = config.GetEffectData(m_data.m_effect_id); if (effect_data == null) { return(null); } ObjectCreationContext object_context = new ObjectCreationContext(); //m_object_proxy_id object_context.m_object_type_id = m_data.m_effect_id; object_context.m_type_data = effect_data; object_context.m_logic_world = logic_world; object_context.m_owner_id = target_entity_id; Effect effect = effect_manager.CreateObject(object_context); return(effect); }
public virtual void BuildLogicWorld(WorldCreationContext world_context) { m_player_manager.SetPstidAndProxyid(world_context.m_pstid2proxyid, world_context.m_proxyid2pstid); IConfigProvider config = GetConfigProvider(); for (int i = 0; i < world_context.m_players.Count; ++i) { ObjectCreationContext context = world_context.m_players[i]; context.m_logic_world = this; context.m_type_data = config.GetObjectTypeData(context.m_object_type_id); context.m_proto_data = config.GetObjectProtoData(context.m_object_proto_id); m_player_manager.CreateObject(context); } OnPlayersCreated(); for (int i = 0; i < world_context.m_entities.Count; ++i) { ObjectCreationContext context = world_context.m_entities[i]; context.m_logic_world = this; context.m_type_data = config.GetObjectTypeData(context.m_object_type_id); context.m_proto_data = config.GetObjectProtoData(context.m_object_proto_id); m_entity_manager.CreateObject(context); } m_player_manager.OnWorldBuilt(); }
protected virtual void PostInitializeObject(ObjectCreationContext context) { }
protected override Effect CreateObjectInstance(ObjectCreationContext context) { return(new Effect()); }
protected override Entity CreateObjectInstance(ObjectCreationContext context) { return(new Entity()); }
protected override void PostInitializeObject(ObjectCreationContext context) { m_definition_component = GetComponent(EffectDefinitionComponent.ID) as EffectDefinitionComponent; }
public WorldCreationContext CreateWorldCreationContext(CombatStartInfo combat_start_info) { WorldCreationContext world_context = new WorldCreationContext(); world_context.m_level_id = combat_start_info.m_level_id; world_context.m_game_mode = combat_start_info.m_game_mode; world_context.m_world_seed = combat_start_info.m_world_seed; //本地玩家 world_context.m_pstid2proxyid[CombatTester.TEST_LOCAL_PLAYER_PSTID] = PlayerManager.LOCAL_PLAYER_PROXYID; world_context.m_proxyid2pstid[PlayerManager.LOCAL_PLAYER_PROXYID] = CombatTester.TEST_LOCAL_PLAYER_PSTID; ObjectCreationContext obj_context = new ObjectCreationContext(); obj_context.m_object_proxy_id = PlayerManager.LOCAL_PLAYER_PROXYID; obj_context.m_object_type_id = 3; obj_context.m_object_proto_id = -1; obj_context.m_is_local = true; world_context.m_players.Add(obj_context); //NPC敌人玩家 long proxy_pstid = PlayerManager.AI_ENEMY_PLAYER_PROXYID; world_context.m_pstid2proxyid[proxy_pstid] = PlayerManager.AI_ENEMY_PLAYER_PROXYID; world_context.m_proxyid2pstid[PlayerManager.AI_ENEMY_PLAYER_PROXYID] = proxy_pstid; obj_context = new ObjectCreationContext(); obj_context.m_object_proxy_id = PlayerManager.AI_ENEMY_PLAYER_PROXYID; obj_context.m_object_type_id = 2; obj_context.m_object_proto_id = -1; world_context.m_players.Add(obj_context); //本地玩家的Entity obj_context = new ObjectCreationContext(); obj_context.m_object_proxy_id = PlayerManager.LOCAL_PLAYER_PROXYID; obj_context.m_object_type_id = 111; obj_context.m_object_proto_id = 111001; obj_context.m_birth_info = new BirthPositionInfo(new FixPoint(-5), new FixPoint(0), new FixPoint(-5), new FixPoint(90)); obj_context.m_is_local = true; world_context.m_entities.Add(obj_context); obj_context = new ObjectCreationContext(); obj_context.m_object_proxy_id = PlayerManager.LOCAL_PLAYER_PROXYID; obj_context.m_object_type_id = 101; obj_context.m_object_proto_id = 101002; obj_context.m_birth_info = new BirthPositionInfo(new FixPoint(-5), new FixPoint(0), new FixPoint(0), new FixPoint(90)); obj_context.m_is_local = true; obj_context.m_is_ai = true; world_context.m_entities.Add(obj_context); obj_context = new ObjectCreationContext(); obj_context.m_object_proxy_id = PlayerManager.LOCAL_PLAYER_PROXYID; obj_context.m_object_type_id = 112; obj_context.m_object_proto_id = 112001; obj_context.m_birth_info = new BirthPositionInfo(new FixPoint(-5), new FixPoint(0), new FixPoint(7), new FixPoint(90)); obj_context.m_is_local = true; obj_context.m_is_ai = true; world_context.m_entities.Add(obj_context); //NPC敌人玩家Entity obj_context = new ObjectCreationContext(); obj_context.m_object_proxy_id = PlayerManager.AI_ENEMY_PLAYER_PROXYID; obj_context.m_object_type_id = 101; obj_context.m_object_proto_id = 101001; obj_context.m_birth_info = new BirthPositionInfo(new FixPoint(5), new FixPoint(0), new FixPoint(0), new FixPoint(90));; world_context.m_entities.Add(obj_context); return(world_context); }
public virtual ObjectBase CreateObject(ObjectCreationContext context) { return(null); }
protected override RenderEntity CreateObjectInstance(ObjectCreationContext context) { return(new RenderEntity(m_render_world)); }
protected override Skill CreateObjectInstance(ObjectCreationContext context) { return(new Skill()); }
protected abstract TObject CreateObjectInstance(ObjectCreationContext context);
public static Entity CreateEntityForSkillAndEffect(Component caller_component, Entity owner_entity, Target projectile_target, Vector3FP position_offset, FixPoint angle_offset, int object_type_id, int object_proto_id, FixPoint object_life_time, EffectGenerator attached_generator) { LogicWorld logic_world = owner_entity.GetLogicWorld(); IConfigProvider config = logic_world.GetConfigProvider(); ObjectTypeData type_data = config.GetObjectTypeData(object_type_id); if (type_data == null) { return(null); } PositionComponent owner_position_cmp = owner_entity.GetComponent(PositionComponent.ID) as PositionComponent; Vector3FP source_pos = owner_position_cmp.CurrentPosition; Vector2FP xz_facing; FixPoint angle; Vector3FP facing; if (projectile_target == null) { xz_facing = owner_position_cmp.Facing2D; angle = owner_position_cmp.FacingAngle; facing.x = xz_facing.x; facing.y = FixPoint.Zero; facing.z = xz_facing.z; } else { Vector3FP target_pos = projectile_target.GetPosition(logic_world); xz_facing.x = target_pos.x - source_pos.x; xz_facing.z = target_pos.z - source_pos.z; xz_facing.Normalize(); angle = xz_facing.ToDegree(); facing = target_pos - source_pos; facing.Normalize(); } Vector2FP side = xz_facing.Perpendicular(); Vector2FP xz_offset = xz_facing * position_offset.z + side * position_offset.x; if (angle_offset != FixPoint.Zero) { angle += angle_offset; FixPoint radian = FixPoint.Degree2Radian(-angle); facing.x = FixPoint.Cos(radian); facing.z = FixPoint.Sin(radian); } Vector3FP birth_position = new Vector3FP(source_pos.x + xz_offset.x, source_pos.y + position_offset.y, source_pos.z + xz_offset.z); BirthPositionInfo birth_info = new BirthPositionInfo(birth_position.x, birth_position.y, birth_position.z, angle, owner_position_cmp.GetCurrentSceneSpace()); ProjectileComponent owner_entity_projectile_component = owner_entity.GetComponent(ProjectileComponent.ID) as ProjectileComponent; if (owner_entity_projectile_component != null) { Entity original_owner = logic_world.GetEntityManager().GetObject(owner_entity_projectile_component.SourceEntityID); if (original_owner != null) { owner_entity = original_owner; } } Player owner_player = owner_entity.GetOwnerPlayer(); ObjectCreationContext object_context = new ObjectCreationContext(); object_context.m_object_proxy_id = owner_player.ProxyID; object_context.m_object_type_id = object_type_id; object_context.m_object_proto_id = object_proto_id; object_context.m_birth_info = birth_info; object_context.m_type_data = type_data; object_context.m_proto_data = config.GetObjectProtoData(object_proto_id); object_context.m_logic_world = logic_world; object_context.m_owner_id = owner_player.ID; object_context.m_is_ai = true; object_context.m_is_local = owner_player.IsLocal; Entity created_entity = logic_world.GetEntityManager().CreateObject(object_context); DeathComponent death_component = created_entity.GetComponent(DeathComponent.ID) as DeathComponent; if (death_component != null && object_life_time > FixPoint.Zero) { death_component.SetLifeTime(object_life_time); } SummonedEntityComponent summoned_component = created_entity.GetComponent(SummonedEntityComponent.ID) as SummonedEntityComponent; if (summoned_component != null) { summoned_component.SetMaster(owner_entity); } ProjectileComponent projectile_component = created_entity.GetComponent(ProjectileComponent.ID) as ProjectileComponent; if (projectile_component != null) { ProjectileParameters param = RecyclableObject.Create <ProjectileParameters>(); param.m_start_time = logic_world.GetCurrentTime(); param.m_life_time = object_life_time; param.m_source_entity_id = owner_entity.ID; param.m_start_position = birth_position; param.m_fixed_facing = facing; if (projectile_target != null) { param.m_target_entity_id = projectile_target.GetEntityID(); param.m_target_position = projectile_target.GetPosition(logic_world); } else { Skill owner_skill = null; SkillComponent skill_componnet = caller_component as SkillComponent; if (skill_componnet != null) { owner_skill = skill_componnet.GetOwnerSkill(); } if (owner_skill != null && owner_skill.GetDefinitionComponent().ExternalDataType == SkillDefinitionComponent.NeedExternalTarget) { param.m_target_entity_id = 0; FixPoint range = owner_skill.GetDefinitionComponent().MaxRange; if (range <= 0) { range = FixPoint.Ten; //ZZWTODO } if (projectile_component.Speed > FixPoint.Zero) { param.m_life_time = range / projectile_component.Speed; } param.m_target_position = param.m_start_position + param.m_fixed_facing * range; } } param.m_generator_id = attached_generator == null ? 0 : attached_generator.ID; projectile_component.InitParam(param); } else if (attached_generator != null) { EffectApplicationData app_data = RecyclableObject.Create <EffectApplicationData>(); app_data.m_original_entity_id = owner_entity.ID; app_data.m_source_entity_id = owner_entity.ID; attached_generator.Activate(app_data, created_entity); RecyclableObject.Recycle(app_data); } return(created_entity); }
protected override void PreInitializeObject(ObjectCreationContext context) { m_entity = context.m_logic_world.GetEntityManager().GetObject(m_context.m_object_id); }