// Start is called before the first frame update public void IntervalResponse(int interval) { if (isAlive) { if (interval >= actionList.Count) { return; } NPCAction action = actionList[interval]; if (!gameObject.activeInHierarchy && action.activeFlag) { gameObject.SetActive(true); activeFlag = true; } if (action.shorthandAction == "w") // walk { Debug.Log("WALKING: " + action.intervalNum); StartCoroutine(walk(action.waypointNum)); //[2,-1] } if (action.shorthandAction == "i") // idle / nothing { } if (action.shorthandAction == "d") // die { kill(0); } if (gameObject.activeInHierarchy && !action.activeFlag) { activeFlag = false; } } }
void GetActionInNPC() { NPCAction action = m_model.m_curNPC.GetAction(); m_model.SetNPCAction(action); m_view.ChangeTestActionTest(m_model); ChangeStateTo(FlowState.ActionEffect); }
protected NPCAction( NPCAction action ) { this.Type = action.Type; this.frameIndex = action.frameIndex; this.IsLoop = action.IsLoop; this.loopCount = action.loopCount; this.intervalFrameCount = action.intervalFrameCount; }
public NPCBehavior(int level) { //NPCのレベル設定も追加したいので受け取った引数に応じて //コンストラクタで振る舞いを切り替えられるようにする if (level == NPCLevel.EasyLevel) { earlyAction += EarlyActionEasy; middleAction += MiddleActionEasy; lateAction += LateActionEasy; } }
public void Init(FlowManager _mgr) { m_mgr = _mgr; m_curNPC = null; m_curAction = null; m_curChoiceList = null; m_curState = FlowState.GetNPC; m_choiceID = -1; m_nextNPC = NPCName.Player; m_nextNPCAction = NPCActionName.PlayerIntro1; }
public override void Update(InputComponent input, FieldCamera camera) { ExecuteAction(); base.Update(input, camera); bool isCollidingWithPlayer = _characterComponent.Collisions.FirstOrDefault(x => x.ColliderB.Entity == Core.Instance.Player.Entity) != null; if (_currentAction != null && _currentTicks == 0 && !isCollidingWithPlayer) { _currentAction.CurrentFrame++; if (_currentAction.CurrentFrame > _currentAction.Frames - 1) { _currentAction = null; } } this.Direction = _previousAnimation.Direction; }
protected void DoAction(NPCAction action) { if (action.name == "Walking") { if (Vector3.Distance(transform.position, action.walkToPoint) >= closeEnoughLimit) { _direction = (action.walkToPoint - transform.position).normalized; _lookRotation = Quaternion.LookRotation(_direction); transform.rotation = Quaternion.Slerp(transform.rotation, _lookRotation, Time.fixedDeltaTime * stats.turnSpeed); transform.position = Vector3.MoveTowards(transform.position, action.walkToPoint, Time.fixedDeltaTime * stats.walkSpeed); } else { waitTimer += Time.fixedDeltaTime; if (waitTimer >= action.wait) { nextAction(); waitTimer = 0f; } } } }
protected void DoAction (NPCAction action) { if (action.name == "Walking") { if (Vector3.Distance (transform.position, action.walkToPoint) >= closeEnoughLimit) { _direction = (action.walkToPoint - transform.position).normalized; _lookRotation = Quaternion.LookRotation (_direction); transform.rotation = Quaternion.Slerp (transform.rotation, _lookRotation, Time.fixedDeltaTime * stats.turnSpeed); transform.position = Vector3.MoveTowards (transform.position, action.walkToPoint, Time.fixedDeltaTime * stats.walkSpeed); } else { waitTimer += Time.fixedDeltaTime; if (waitTimer >= action.wait) { nextAction (); waitTimer = 0f; } } } }
private void DoAction(NPCAction action) { if(action.type == NPCAction.ActionType.Walking) { if(Vector3.Distance(transform.position, action.dest) >= closeEnoughLimit) { agent.SetDestination(action.dest); } else { waitTimer += Time.fixedDeltaTime; if(waitTimer >= action.waitTime) { nextAction(); waitTimer = 0f; } } } }
public void AddNPCAction(NPCAction _ac) { m_actionList.Add(_ac); }
private List <Dictionary <string, string> > m_fullDic = new List <Dictionary <string, string> >(); // every item info from DB public NPCActionFactory(NPCActionChoiceFactory _choiceFactory) { m_actionList = new List <NPCAction>(); m_actionStList = new List <NPCActionNameSt>(); m_actionWithParentList = new List <NPCActionWithParentID>(); ReadNameDataFromXml(); // Name Table 읽어오기 for (int i = 0; i < m_fullDic.Count; i++) { m_actionStList.Add(new NPCActionNameSt(m_fullDic[i])); } // Name Table 저장 for (int i = 0; i < _choiceFactory.m_choiceWithParentList.Count; i++) { NPCActionChoiceWithParentID parentWithID = _choiceFactory.m_choiceWithParentList[i]; NPCActionChoice choice = parentWithID.m_npcActionChoice; int parentID = parentWithID.m_parentActionID; // parentID = DB에서 프라이머리 키, 자동할당 따라서 내 임의대로 안됨. 그래서 따로 바꿔줘야 함 for (int k = 0; k < m_actionStList.Count; k++) { NPCActionNameSt nameST = m_actionStList[k]; int givenID = -1; if (nameST.GetGivenID(parentID) == -1) { continue; } givenID = nameST.m_givenID; choice.m_parentNPCActionName = (NPCActionName)givenID; break; } } // 이전 단계에서 Parent에 대해서 ID와 GivenID 알 수 없었기 때문에 여기에서 초기화 해준다. m_fullDic.Clear(); // 재활용을 위해서 ReadDataFromXml(); // 정보 읽어오기 int numOfAction = Enum.GetNames(typeof(NPCActionName)).Length; for (int i = 0; i < numOfAction; i++) { string name = "NPCAction" + i.ToString(); object obj = Activator.CreateInstance(Type.GetType(name)); NPCAction action = (NPCAction)obj; m_actionList.Add(action); } // 스크립트가 다 따로 있기 때문에 현재 이런 방식으로 하고 있음. // 스크립트 이름이 다르기 때문에 만들었음. // 순서는 givenID를 Enum Casting한 것과 똑같다. for (int i = 0; i < m_fullDic.Count; i++) { Dictionary <string, string> data = m_fullDic[i]; int id = int.Parse(data["NPCActionName"]); int givenID = -1; for (int k = 0; k < m_actionStList.Count; k++) { if (m_actionStList[k].GetGivenID(id) == -1) { continue; } givenID = m_actionStList[k].m_givenID; break; } NPCAction properAction = m_actionList[givenID]; properAction.Init(data); // 몇 개의 데이터만 초기화 된다. F12들어가서 보면 확인가능 properAction.m_npcActionName = (NPCActionName)givenID; // ID는 GivenID로 형변환 해야한다. int parentNPCID = int.Parse(data["ParentNPC"]); NPCActionWithParentID actionWithParent = new NPCActionWithParentID(properAction, parentNPCID); m_actionWithParentList.Add(actionWithParent); } for (int i = 0; i < _choiceFactory.m_actionChoiceList.Count; i++) { NPCActionChoice choice = _choiceFactory.m_actionChoiceList[i]; for (int k = 0; k < m_actionList.Count; k++) { NPCAction action = m_actionList[k]; if (action.m_npcActionName != choice.m_parentNPCActionName || action.m_npcActionName == NPCActionName.None) { continue; } action.AddChoice(choice); break; } } m_fullDic = null; }
public NPCActionWithParentID(NPCAction _action, int _parentID) { m_npcAction = _action; m_parentNPCID = _parentID; }
private List <Dictionary <string, string> > m_fullDic = new List <Dictionary <string, string> >(); // every item info from DB public NPCFactory(NPCActionFactory _actionFactory) { m_npcList = new List <NPC>(); m_npcStList = new List <NPCNameSt>(); ReadNameDataFromXml(); // NameTable 읽어오기 for (int i = 0; i < m_fullDic.Count; i++) { m_npcStList.Add(new NPCNameSt(m_fullDic[i])); } // 데이터 저장 m_fullDic.Clear(); // 재사용 위해서 클리어 for (int i = 0; i < _actionFactory.m_actionWithParentList.Count; i++) { NPCActionWithParentID actionWithParent = _actionFactory.m_actionWithParentList[i]; NPCAction action = actionWithParent.m_npcAction; int parentID = actionWithParent.m_parentNPCID; // parentID = DB에서 프라이머리 키, 자동할당 따라서 내 임의대로 안됨. 그래서 따로 바꿔줘야 함 int givenID = -1; for (int k = 0; k < m_npcStList.Count; k++) { if (m_npcStList[k].GetGivenID(parentID) == -1) { continue; } givenID = m_npcStList[k].m_givenID; break; } action.m_parentNPCName = (NPCName)givenID; } // 이전 단계에서 마저 초기화 하지 못했던 부모 초기화 ReadDataFromXml(); //NPC 데이터 읽어오기 int numOfNPC = Enum.GetNames(typeof(NPCName)).Length; for (int i = 0; i < numOfNPC; i++) { string name = "NPC" + i.ToString(); object obj = Activator.CreateInstance(Type.GetType(name)); NPC npc = (NPC)obj; m_npcList.Add(npc); } for (int i = 0; i < m_fullDic.Count; i++) { Dictionary <string, string> data = m_fullDic[i]; int id = int.Parse(data["ID"]); int givenID = -1; for (int k = 0; k < m_npcStList.Count; k++) { if (m_npcStList[k].GetGivenID(id) == -1) { continue; } givenID = m_npcStList[k].m_givenID; break; } NPC properNPC = m_npcList[givenID]; properNPC.Init(data); // 몇 개의 데이터만 초기화. 들어가서 확인하면 된다. properNPC.m_npcName = (NPCName)givenID; } // NPC 초기화 완료 // Action을 이제 NPC에 넣는다. for (int i = 0; i < _actionFactory.m_actionList.Count; i++) { NPCAction action = _actionFactory.m_actionList[i]; for (int k = 0; k < m_npcList.Count; k++) { NPC npc = m_npcList[k]; if (npc.m_npcName != action.m_parentNPCName) { continue; } npc.AddNPCAction(action); break; } } }
public float GetActionValue(NPCAction action) { return(0.0f); }
public bool GetActionUp(NPCAction action) { return(false); }
void doNPCAction(NPCAction npcAction) { switch (npcAction.actionType) { case NPCAction.ActionType.Action: { break; } case NPCAction.ActionType.Move: { Vector2 distance = npcAction.moveDestinationTransform.GetComponent<RectTransform>().position - transform.GetComponent<RectTransform>().position; if(Mathf.Abs (distance.sqrMagnitude) > .05 && localGameManager.isNotPaused == 1) { findCurrentAnimation("move"); move (distance.normalized); } else { findCurrentAnimation("idle"); } break; } case NPCAction.ActionType.Turn: { break; } default: { findCurrentAnimation("idle"); break; } } }
protected void ExecuteAction() { if (ActionList.Count == 0 && _currentAction == null) { ActionList.Add(new NPCAction() { Action = EActionTypes.Idle, Direction = _previousAnimation.Direction, Frames = 1 }); } if (_currentAction == null) { _currentAction = ActionList.First(); if (_currentAction.CurrentFrame < _currentAction.InitialFrame) { _currentAction.CurrentFrame = _currentAction.InitialFrame; } ActionList.RemoveAt(0); if (RepeatActions) { ActionList.Add(new NPCAction(_currentAction)); } } //Handle movement if any _movementComponent.Direction = new Vector3(0, 0, 0); if (_currentAction.Action == EActionTypes.Walk || _currentAction.Action == EActionTypes.Run) { var direction = new Vector3(); if (_currentAction.Direction == ECameraDirection.North) { direction.Z = -1; } if (_currentAction.Direction == ECameraDirection.NorthEast) { direction.Z = -1; } if (_currentAction.Direction == ECameraDirection.East) { direction.Z = 0; } if (_currentAction.Direction == ECameraDirection.SouthEast) { direction.Z = 1; } if (_currentAction.Direction == ECameraDirection.South) { direction.Z = 1; } if (_currentAction.Direction == ECameraDirection.SouthWest) { direction.Z = 1; } if (_currentAction.Direction == ECameraDirection.West) { direction.Z = 0; } if (_currentAction.Direction == ECameraDirection.SouthWest) { direction.Z = -1; } if (_currentAction.Direction == ECameraDirection.North) { direction.X = 0; } if (_currentAction.Direction == ECameraDirection.NorthEast) { direction.X = 1; } if (_currentAction.Direction == ECameraDirection.East) { direction.X = 1; } if (_currentAction.Direction == ECameraDirection.SouthEast) { direction.X = 1; } if (_currentAction.Direction == ECameraDirection.South) { direction.X = 0; } if (_currentAction.Direction == ECameraDirection.SouthWest) { direction.X = -1; } if (_currentAction.Direction == ECameraDirection.West) { direction.X = -1; } if (_currentAction.Direction == ECameraDirection.SouthWest) { direction.X = -1; } _movementComponent.Direction = direction; _movementComponent.Running = _currentAction.Action == EActionTypes.Run; _movementComponent.BeginJump = _currentAction.Action == EActionTypes.Jump && !_movementComponent.Jumping; } }
public void SetNPCAction(NPCAction _curNPCAction) { m_curAction = _curNPCAction; }
private string SetNPCToDoSomeThing(NPC npc, NPCAction selectV) { switch (selectV) { case NPCAction.Bust: { /* * 0代表破产 */ var players = this.getGetAllPlayers(); string keyToSetBust; if (SuitToSetBust(npc, players, out keyToSetBust)) { /* * 如果适合破产,将设置破产 */ NpcDebugWrite($"{npc.PlayerName}({npc.Key})可以bust,其要对{this._Players[keyToSetBust].PlayerName}({keyToSetBust})进行破产清算!!!"); var sb = new SetBust() { c = "SetBust", Key = npc.Key, target = this._Players[keyToSetBust].StartFPIndex, targetOwner = keyToSetBust }; return(updateBust(sb)); } else { NpcDebugWrite($"{npc.PlayerName}({npc.Key})不可以bust"); //执行攻击 return(SetNPCToDoSomeThing(npc, NPCAction.Attack)); } }; case NPCAction.Attack: { // lock (this.PlayerLock) { npc.ClearEnemiesAndMolester(this._Players); if (npc.SuitToAttack()) { if (npc.Enemies.Count > 0) { string enemyKey = npc.Enemies[this.rm.Next(npc.Enemies.Count)]; NpcDebugWrite($"{npc.PlayerName}({npc.Key})可以Attack,其要对{this._Players[enemyKey].PlayerName}({enemyKey})进行攻击!!!"); var sa = new SetAttack() { c = "SetAttack", Key = npc.Key, target = this._Players[enemyKey].StartFPIndex, targetOwner = enemyKey }; return(updateAttack(sa)); } else if (npc.Molester.Count > 0) { string molesterKey = npc.Molester[this.rm.Next(npc.Molester.Count)]; NpcDebugWrite($"{npc.PlayerName}({npc.Key})可以Attack,其要对{this._Players[molesterKey].PlayerName}({molesterKey})进行攻击!!!"); var sa = new SetAttack() { c = "SetAttack", Key = npc.Key, target = this._Players[molesterKey].StartFPIndex, targetOwner = molesterKey }; return(updateAttack(sa)); } else { NpcDebugWrite($"{npc.PlayerName}({npc.Key})不可以Attack"); return(SetNPCToDoSomeThing(npc, NPCAction.Tax)); } } else { NpcDebugWrite($"{npc.PlayerName}({npc.Key})不可以Attack"); return(SetNPCToDoSomeThing(npc, NPCAction.Tax)); } } }; case NPCAction.Tax: { if (npc.SuitToCollectTax()) { var taxInPositions = npc.TaxInPositionForeach(); var position = -1; double minLength = double.MaxValue; for (int indexOfTaxPosition = 0; indexOfTaxPosition < taxInPositions.Count; indexOfTaxPosition++) { var length = Distance(taxInPositions[indexOfTaxPosition], npc.StartFPIndex); if (length < minLength) { minLength = length; position = taxInPositions[indexOfTaxPosition]; } } if (position >= 0) { NpcDebugWrite($"{npc.PlayerName}({npc.Key})可以Tax,其要对{ Program.dt.GetFpByIndex(position).FastenPositionName}进行收取红包!!!"); var st = new SetTax() { c = "SetTax", target = position, Key = npc.Key }; return(updateTax(st)); } else { NpcDebugWrite($"{npc.PlayerName}({npc.Key})不可以Tax"); return(SetNPCToDoSomeThing(npc, NPCAction.Collect)); } } else { NpcDebugWrite($"{npc.PlayerName}({npc.Key})不可以Tax"); return(SetNPCToDoSomeThing(npc, NPCAction.Collect)); } }; case NPCAction.Collect: { // lock (this.PlayerLock) { npc.ClearEnemiesAndMolester(this._Players); if (npc.SuitToCollect()) { // var collectInPositions = npc.TaxInPositionForeach(); var position = -1; var collectIndex = -1; double minLength = double.MaxValue; foreach (var item in this._collectPosition) { if (item.Value >= 0) { var length = Distance(item.Value, npc.StartFPIndex); if (length < minLength) { minLength = length; position = item.Value; collectIndex = item.Key; } } } if (collectIndex >= 0) { NpcDebugWrite($"{npc.PlayerName}({npc.Key})可以SetCollect"); var ut = new SetCollect() { c = "SetCollect", collectIndex = collectIndex, cType = "findWork", fastenpositionID = Program.dt.GetFpByIndex(position).FastenPositionID, Key = npc.Key }; return(updateCollect(ut)); } else { return(SetNPCToDoSomeThing(npc, NPCAction.Wait)); } } else { return(SetNPCToDoSomeThing(npc, NPCAction.Wait)); } } }; case NPCAction.Wait: { if (npc.getCar().state == Car.CarState.waitForCollectOrAttack) { var otr = new CommonClass.OrderToReturn() { c = "OrderToReturn", Key = npc.Key }; return(OrderToReturn(otr)); } else if (npc.getCar().state == Car.CarState.waitForTaxOrAttack) { var otr = new CommonClass.OrderToReturn() { c = "OrderToReturn", Key = npc.Key }; return(OrderToReturn(otr)); } else if (npc.getCar().state == Car.CarState.waitOnRoad) { var otr = new CommonClass.OrderToReturn() { c = "OrderToReturn", Key = npc.Key }; return(OrderToReturn(otr)); } else { return(""); } }; default: { return(""); } } }