private MonsterCreature GetMonsterCreature(PNmlMonster monsterData) { MonsterCreature monster = null; List <MonsterCreature> list = m_deadMonsterCreatureDic.Get(monsterData.monster); if (list != null && list.Count > 0) { monster = list[0]; monster.monsterUID = monsterData.uid; list.RemoveAt(0); } if (monster == null) { monster = MonsterCreature.CreateBordlandMonster(monsterData, Vector3.zero, new Vector3(0f, 90f, 0f)); } if (!monster) { return(null); } if (!monster.gameObject) { Logger.LogError("monster is valid ,but monster gameobject is null ,monster mesh is {0}", monsterData.mesh); monster.Destroy(); return(null); } monster.enableUpdate = false; monster.gameObject?.SetActive(true); return(monster); }
private void CreateMonsterCreature(PNmlMonster[] datas) { StopCreateMonster(); m_loadMonsterCoroutine = Level.PrepareAssets(GetMonsterPreloadAssets(datas), (flag) => { if (!flag) { Logger.LogError("borderland player assets isn't prepare....."); return; } for (int i = 0; i < datas.Length; i++) { PNmlMonster data = datas[i]; if (!m_bordlandMonster.ContainsKey(data.uid)) { continue; } MonsterCreature monster = GetMonsterCreature(data); HandleMonster(monster, data); } }); }
private void AddDeadMonsterCreature(MonsterCreature monster) { if (!m_deadMonsterCreatureDic.ContainsKey(monster.monsterId)) { m_deadMonsterCreatureDic.Add(monster.monsterId, new List <MonsterCreature>()); } List <MonsterCreature> list = m_deadMonsterCreatureDic.Get(monster.monsterId); list.Add(monster); }
/// <summary> /// 延迟处理怪物,等待资源加载完毕 /// </summary> /// <param name="monster"></param> public void HandleMonster(MonsterCreature monster, PNmlMonster data) { if (!monster || !monster.gameObject || !monster.behaviour || !monster.activeRootNode) { return; } monster.behaviour.enabled = false; monster.behaviour.collider_.syncPosition = false; monster.behaviour.collider_.transform.localPosition = Vector3.zero; Util.SetLayer(monster.gameObject, Layers.MODEL); monster.gameObject.name = Util.Format("monster_{0}_{1}_{2}", data.uid, (EnumBordlandMonsterType)data.type, data.boss); monster.isPlayer = false; BordlandsCreature bc = monster.activeRootNode.GetComponentDefault <BordlandsCreature>(); bc.LoadMonsterRuntimeAnimator(BORDLAND_MONSTER_ANIMATOR_NAME, data); bc.moveSpeed = GetMonsterMoveSpeed(data.mesh); bc.creature = monster; bc.ResetToOriginal(); bc.SetMonsterRandomDir(); bc.InitPVECreatureBehaviour(); bc.CreateCollider(); Vector3 pos = data.pos.ToVector3(); Vector4 levelEdge = bordlandsEdge; if (levelEdge.z == levelEdge.w) { levelEdge = new Vector4(-22f, 22f, -1.4f, 2f); m_edge = levelEdge; } // edge check if (levelEdge.x != 0 || levelEdge.x != levelEdge.y) { pos.x = Mathf.Clamp(pos.x, levelEdge.x, levelEdge.y); } if (levelEdge.z != 0 || levelEdge.z != levelEdge.w) { pos.z = Mathf.Clamp(pos.z, levelEdge.z, levelEdge.w); } bc.creaturePos = pos; if (!m_monsterCreature.ContainsKey(data.uid)) { m_monsterCreature.Add(data.uid, bc); } else { m_monsterCreature[data.uid] = bc; } }
public static RobotCreature Create(CreatureInfo info, Vector3_ pos, Vector3 rot, string name = "", string uiName = "") { if (info == null) { Logger.LogError("RobotCreature::Create: Create robot failed, invalid config"); return(null); } var rootNode = new GameObject().transform; if (!CreateMorphNodes(info, rootNode)) { Logger.LogError("RobotCreature::Create: Create robot [{0}:{1}] failed, main model [{2}] not loaded", info.ID, info.name, CreatureInfo.GetMorphModelName(info.models, 0)); return(null); } rootNode.position = pos; rootNode.eulerAngles = rot; // Protect invalid weapon config if (info.weaponID < 1) { info.weaponID = 1; info.weaponItemID = 1101; } var c = Create <RobotCreature>(string.IsNullOrEmpty(name) ? info.name : name, rootNode.gameObject); c.InitPosition(pos); c.isPlayer = false; c.isMonster = false; c.isRobot = true; c.isCombat = true; c.creatureCamp = CreatureCamp.MonsterCamp; // 机器人默认必须是怪物的阵营 c.uiName = string.IsNullOrEmpty(uiName) ? c.name : uiName; c.isDead = false; c.realDead = false; c.useSpringBone = true; c.teamIndex = MonsterCreature.GetMonsterRoomIndex(); c.UpdateConfig(info); c.OnCreate(info.buffs); return(c); }
public void UpdateBattleItemPos() { if (m_battleStoryDic == null || m_battleStoryDic.Count == 0 || _CameraShake.isShaking || combatCameraMoving) { return; } Dictionary <Creature, BaseBattleItem> .Enumerator e = m_battleStoryDic.GetEnumerator(); while (e.MoveNext()) { if (e.Current.Key is MonsterCreature) { MonsterCreature monster = e.Current.Key as MonsterCreature; UIFollowTarget uiFollow = Window_HpSlider.GetFollowScript(monster); if (e.Current.Value == null || !e.Current.Value.transform || uiFollow == null || !m_monsterCamera) { continue; } e.Current.Value.transform.position = uiFollow.transform.position; //pos = e.Current.Value.transform.localPosition + m_offset; //e.Current.Value.transform.localPosition = pos; SetUIArea(e.Current.Value.rectTransform, m_screenRect, UIManager.canvas.rectTransform()); } else { if (e.Current.Value == null || !e.Current.Value.transform || !m_monsterCamera) { continue; } Vector3 worldpos = e.Current.Key.position; worldpos.y += 2.15f;//设置气泡高度 Vector3 pos = m_monsterCamera.WorldToScreenPoint(worldpos); //must change build.screenPos.z as item position.z pos.z = e.Current.Value.transform.position.z; pos = m_uiCamera.ScreenToWorldPoint(pos); e.Current.Value.transform.position = pos; //pos = e.Current.Value.transform.localPosition + m_offset; //e.Current.Value.transform.localPosition = pos; SetUIArea(e.Current.Value.rectTransform, m_screenRect, UIManager.canvas.rectTransform()); } } }
protected override void AfterCreateMonster(MonsterCreature monster) { base.AfterCreateMonster(monster); monsterBoss = monster; m_times = 0; moduleUnion.m_inUnionPve = true; if (moduleUnion.m_isUnionBossTask && moduleUnion.BossInfo.bossstate == 1) { moduleUnion.m_bossOpen = true; monster.maxHealth = moduleUnion.m_bossStage.bossHP; monster.health = moduleUnion.BossInfo.remianblood; } else { var state = moduleUnion.BossInfo.remianblood <= 0 ? PVEOverState.Success : PVEOverState.GameOver; modulePVE.SendPVEState(state); } monster.AddEventListener(CreatureEvents.DEAD, UnionBossRealDeath); }
public Creature CreateSceneActor(int rMonsterId, Vector3_ rPos, CreatureDirection rDir, int rGroup, int rLevel) { MonsterCreature actor = MonsterCreature.CreateMonster(rMonsterId, rGroup, rLevel, rPos, Vector3_.zero); if (!actor) { return(null); } actor.isBoss = false; actor.enabledAndVisible = true; actor.invincibleCount = int.MaxValue; actor.behaviour.hitCollider.isTrigger = false; actor.checkEdge = false; actor.SetHealthBarVisible(false); actor.forceDirection = (int)rDir; return(actor); }
/// <summary> /// 创建monster/sceneactor /// </summary> /// <param name="b"></param> private void RealCreateMonster(SceneEventInfo.SceneBehaviour b) { if (b.sceneBehaviorType == SceneEventInfo.SceneBehaviouType.CreateMonster) { SCreateMonsterBehaviour cmb = new SCreateMonsterBehaviour(b, null); MonsterCreature monster = MonsterCreature.CreateMonster(cmb.monsterId, cmb.group, cmb.level, Vector3_.right * cmb.reletivePos, new Vector3(0, 90f, 0), Module_PVE.instance?.currrentStage); if (!monster) { return; } monster.enabledAndVisible = false; if (sceneRoot) { monster.transform.SetParent(sceneRoot); } creaturePool.Add(monster); } else if (b.sceneBehaviorType == SceneEventInfo.SceneBehaviouType.CreateSceneActor) { SCreateSceneActorBehaviour csab = new SCreateSceneActorBehaviour(b, null); MonsterCreature monster = MonsterCreature.CreateMonster(csab.sceneActorId, csab.group, csab.level, Vector3_.zero + Vector3_.right * csab.reletivePos, new Vector3(0, 90f, 0), Module_PVE.instance?.currrentStage); monster.roleId = (ulong)csab.logicId; if (!monster) { return; } monster.enabledAndVisible = false; if (sceneRoot) { monster.transform.SetParent(sceneRoot); } sceneActorPool.Add(monster); } }
public static FollowTargetEffect Create(StateMachineInfo.FollowTargetEffect effInfo, Transform node, Creature target, Vector3_ position, Creature source = null, Buff sourceBuff = null) { var eff = Create <FollowTargetEffect>(effInfo.effect, effInfo.effect, position + effInfo.motionData.offset, (node.rotation * Quaternion.Euler(effInfo.rotation)).eulerAngles); eff.enableUpdate = true; eff.source = source; eff.follow = false; eff.m_time = 0; eff.offset = effInfo.motionData.offset; eff.target = target; eff.sourceBuff = sourceBuff; eff.triggerType = effInfo.triggerType; eff.m_originEular = eff.localEulerAngles; eff.localScale = effInfo.scale; eff.velocity = effInfo.motionData.velocity; eff.acceleration = effInfo.motionData.acceleration; eff.randomPosition = eff.position_ = position + effInfo.motionData.offset; eff.motion = new Motion_SlantingThrow(eff, target, effInfo.motionData); eff.lifeTime = -1; //粒子系统要更改粒子节点才能改其缩放。搞不懂为什么 var particles = eff.transform.GetComponentsInChildren <ParticleSystem>(); if (particles != null && particles.Length > 0) { for (var i = 0; i < particles.Length; i++) { particles[i].transform.localScale = effInfo.scale; } } eff.transform.SetParent(null); if (effInfo.randomPosition) { var p = eff.position_; eff.randomPosition = new Vector3_(p.x + 1.5 * moduleBattle._Range(-1.0, 1.0), p.y + 1.5 * moduleBattle._Range(0, 1.0)); eff.startPos = eff.randomPosition; } else { eff.startPos = eff.position_; } if (sourceBuff != null) { eff.m_buffCheck = sourceBuff.version; eff.lifeTime = -1; } else { eff.m_buffCheck = 0; } eff.m_inverted = source && !source.isForward; eff.UpdateInvert(); eff.InitTrigger(); #if AI_LOG eff.logId = MonsterCreature.GetMonsterRoomIndex(); Module_AI.LogBattleMsg(source, "create a FollowTargetEffect[logId: {0}] with target {0} startPos {1}, lifeTime = {1} startForward is {2}", eff.logId, eff.position_, eff.lifeTime, eff.startForward); #endif return(eff); }
public static FlyingEffect Create(StateMachineInfo.FlyingEffect effInfo, Creature source, int overrideForward, bool invert, StateMachineInfo.Effect hitEffect, Vector3_ root, Vector3_ rootEular, Vector3 rootRot) { var fe = ConfigManager.Get <FlyingEffectInfo>(effInfo.effect); if (!fe) { Logger.LogWarning("FlyingEffect::Create: Could not create flying effect [{0}], could not find effect config from config_flyingEffectInfos", effInfo.effect); return(null); } FightRecordManager.RecordLog <LogString>(log => { log.tag = (byte)TagType.CreateFlyEffect; log.value = fe.effect; }); var off = effInfo.offset * 0.1; if (invert) { off.x = -off.x; off.z = -off.z; } var direction = effInfo.direction; var rotation = effInfo.rotation; direction.Set(direction.z, direction.y, -direction.x); rotation.Set(-rotation.x, rotation.y, rotation.z); var eular = rootEular + direction; eular.z = Mathd.ClampAngle(eular.z); var z = Mathd.AngToRad(eular.z); var dir = new Vector3_(Mathd.Cos(z), -Mathd.Sin(z)); var pos = root + off; var eff = Create <FlyingEffect>(fe.effect, fe.effect, pos, rotation); eff.enableUpdate = true; if (invert) { dir.x = -dir.x; } eff.sourceBuff = null; eff.follow = false; eff.m_inherit = false; eff.m_time = 0; eff.m_originEular = eff.localEulerAngles; eff.lockForward = Vector3.zero; eff.startForward = overrideForward == 0 ? !source || source.isForward : overrideForward > 0; eff.m_curSectionIdx = 0; eff.m_curActivedSection = -1; eff.m_curSubEffectIdx = 0; eff.m_curSoundEffectIdx = 0; eff.m_curShakeIdx = 0; eff.m_groundHited = false; eff.m_renderTime = 0; eff.effectInfo = fe; eff.source = source; eff.position_ = pos; eff.velocity = effInfo.velocity * 0.0001; eff.acceleration = effInfo.acceleration * 0.0001; eff.lifeTime = fe.lifeTime; eff.hitEffect = hitEffect; eff.CreateCollider(rootRot, dir, eular); eff.m_inverted = invert; eff.UpdateInvert(); #if AI_LOG eff.logId = MonsterCreature.GetMonsterRoomIndex(); Module_AI.LogBattleMsg(source, "create a flying effect[logId:{0}] with pos {1}, lifeTime = {2} startForward is {3}", eff.logId, eff.position_, eff.lifeTime, eff.startForward); #endif return(eff); }
public static PetCreature Create(Creature parent, PetInfo info, Vector3_ pos, Vector3 rot, bool player = false, string name = "", string uiName = "", bool combat = true, bool useSpringBone = true) { if (info == null) { Logger.LogError("PetCreature::Create: Create pet failed, invalid config info"); return(null); } var petInfo = info.BuildCreatureInfo(); if (petInfo == null) { Logger.LogError("PetCreature::Create Create pet [{0}] failed, invalid config info", info.ID); return(null); } var rootNode = new GameObject().transform; if (!CreateMorphNodes(petInfo, rootNode)) { Logger.LogError("PetCreature::Create: Create pet [{0}:{1}] failed, main model [{2}] not loaded", info.ID, petInfo.name, CreatureInfo.GetMorphModelName(petInfo.models, 0)); return(null); } rootNode.position = pos; rootNode.eulerAngles = rot; var c = Create <PetCreature>(string.IsNullOrEmpty(name) ? petInfo.name : name, rootNode.gameObject); c.InitPosition(pos); c.petInfo = info; c.ParentCreature = parent; c.isPlayer = player; c.isMonster = false; c.isCombat = combat; c.isRobot = false; c.creatureCamp = parent ? parent.creatureCamp : CreatureCamp.PlayerCamp; c.uiName = string.IsNullOrEmpty(uiName) ? c.name : uiName; c.isDead = false; c.realDead = false; c.useSpringBone = useSpringBone; c.UpdateConfig(petInfo); c.behaviour.UpdateAllColliderState(false); c.behaviour.attackCollider.enabled = true; c.teamIndex = MonsterCreature.GetMonsterRoomIndex(); c.Buffs = info.GetBuff(info.AdditiveLevel); c.OnCreate(info.GetInitBuff()); c.avatar = info.UpGradeInfo.icon; c.skills.Clear(); var skill = info.GetSkill(); if (skill != null) { c.skills.Add(skill.state, PetSkillData.Create(skill)); } return(c); }