//------------------------------------------------------------------------------------------------------- /** * @brief 添加玩家(木偶) * @param strName 名称 * @param nJob 职业 * @param nSex 性别 * @param propList 外观属性 * @param bMainHost 是否是主角对象 */ public IPuppet AddPuppet(string strName, int nJob, int nSex, EntityViewProp[] propList, bool bMainHost = false) { EntityCreateData data = new EntityCreateData(); data.ID = ++m_uEntityID; data.strName = strName; int speed = 0; Client.IPlayer player = ClientGlobal.Instance().MainPlayer; if (player != null) { speed = player.GetProp((int)WorldObjProp.MoveSpeed); } data.PropList = new EntityAttr[(int)PuppetProp.End - (int)EntityProp.Begin]; int index = 0; data.PropList[index++] = new EntityAttr((int)PuppetProp.Job, nJob); data.PropList[index++] = new EntityAttr((int)PuppetProp.Sex, nSex); data.PropList[index++] = new EntityAttr((int)EntityProp.BaseID, 0); data.PropList[index++] = new EntityAttr((int)WorldObjProp.MoveSpeed, speed); data.ViewList = propList; IEntitySystem es = ClientGlobal.Instance().GetEntitySystem(); if (es == null) { Engine.Utility.Log.Error("严重错误:EntitySystem is null!"); return(null); } IPuppet entity = es.CreateEntity(EntityType.EntityType_Puppet, data) as IPuppet; if (entity == null) { Engine.Utility.Log.Error("AddEntity:创建家园对象失败!"); return(null); } if (bMainHost) { IControllerSystem cs = ClientGlobal.Instance().GetControllerSystem(); if (cs == null) { return(null); } cs.GetActiveCtrl().SetHost(entity); CameraFollow.Instance.target = entity; } m_dicPuppet.Add((int)entity.GetID(), entity); return(entity); }
public void RemoveEntity(IPuppet puppet) { if (puppet == null) { return; } IEntitySystem es = ClientGlobal.Instance().GetEntitySystem(); if (es == null) { return; } m_dicPuppet.Remove((int)puppet.GetID()); es.RemoveEntity(puppet); }