//************************** CHECK ************************************* public static void CheckComplitionIdle(ModelNPC.PersonData dataNPC, GameActionPersonController controller) { if (dataNPC == null) { string strErr = "########## CheckComplitionIdle dataNPC == null "; if (controller != null) { strErr += controller.gameObject.name; } Debug.Log(strErr); return; } float timeWait = (dataNPC as ModelNPC.GameDataAlien).TimeEndCurrentAction; if (Time.time > timeWait) { GetAlienData(dataNPC).TimeEndCurrentAction = -1; RequestActionNPC(dataNPC, NameActionsPerson.Completed, controller); //IdleLock } //FIXANIM if (controller != null) { controller.PlayAnimationIdle(); } }
public static void CheckComplitionIdleLock(ModelNPC.PersonData dataNPC, GameActionPersonController controller) { if (controller == null) { //TEST RequestActionNPC(dataNPC, NameActionsPerson.Completed, controller); return; } float timeWait = (dataNPC as ModelNPC.GameDataAlien).TimeEndCurrentAction; //if (Time.time > controller.TimeIdleLock && p_nameAction == NameActionsPerson.Idle) if (Time.time > timeWait) { GetAlienData(dataNPC).TimeEndCurrentAction = -1; RequestActionNPC(dataNPC, NameActionsPerson.Completed, controller); //IdleLock } //FIXANIM if (controller != null) { controller.PlayAnimationIdle(); } }
public static void CheckComplitionWork(ModelNPC.PersonData dataNPC, GameActionPersonController controller) { if (controller != null) { controller.PlayAnimationWork(); } float timeWait = (dataNPC as ModelNPC.GameDataAlien).TimeEndCurrentAction; if (Time.time > timeWait) //time end animation and completed work { GetAlienData(dataNPC).TimeEndCurrentAction = -1; if (dataNPC.Job != null) { //dataNPC.Job.IsJobRun = false; //dataNPC.Job.IsJobCompleted = true; //dataNPC.CurrentAction = NameActionsPerson.CompletedLoot.ToString(); //if (p_dataNPC.CurrentAction == GameActionPersonController.NameActionsPerson.CompletedLoot.ToString()) ExecuteActionNPC(dataNPC, NameActionsPerson.CompletedLoot, controller); } else { RequestActionNPC(dataNPC, NameActionsPerson.Completed, controller); } } }
public static void ActionTargetLocal(ModelNPC.PersonData dataNPC, GameActionPersonController controller) { string tempID = dataNPC.TargetID; GetAlienData(dataNPC).OnTargetCompleted(); string id = GetAlienData(dataNPC).BaseLockedTargetID; bool isNotBaseLocked = string.IsNullOrEmpty(id); //if (controller != null && string.IsNullOrEmpty(controller.TempLockedTargetID)) if (controller != null && isNotBaseLocked) { //Save ID //controller.TempLockedTargetID = tempID; // dataNPC.TargetID; GetAlienData(dataNPC).BaseLockedTargetID = tempID; } dataNPC.SetTargetPosition(); ExecuteActionNPC(dataNPC, NameActionsPerson.Move, controller); if (controller != null) { controller.DrawRayTarget(); //TEST } }
public static void EndAction(ModelNPC.PersonData dataNPC, GameActionPersonController controller) { if (controller != null) { controller.ActionPerson = NameActionsPerson.Completed; } dataNPC.CurrentAction = NameActionsPerson.Completed.ToString(); }
public static bool ActionWork(ModelNPC.PersonData dataNPC, GameActionPersonController controller) { float tilme = GetAlienData(dataNPC).TimeEndCurrentAction; if (tilme == -1) { GetAlienData(dataNPC).TimeEndCurrentAction = Time.time + TimeWork; } return(false); }
public static void ExecuteActionNPC(ModelNPC.PersonData dataNPC, NameActionsPerson p_nameAction, GameActionPersonController controller, bool isForce = false) { if (isForce && controller != null) { controller.ResetAction(); } if (controller != null) { controller.ActionPerson = p_nameAction; } dataNPC.CurrentAction = p_nameAction.ToString(); }
public static void ActionMove(ModelNPC.PersonData dataNPC) { Vector3 oldPosition = dataNPC.Position; float step = dataNPC.Speed + Storage.SceneDebug.SettingsScene.SpeedMovePersonInDream;// / 3; // * Time.deltaTime; if (step < 0.5f) { step = 0.5f; } if (step > 10f) { step = 10f; } Vector3 targetPosition = dataNPC.TargetPosition; Vector3 newPosition = Vector3.MoveTowards(oldPosition, dataNPC.TargetPosition, step); newPosition = new Vector3(newPosition.x, newPosition.y, oldPosition.z); string fieldOld_Name = Helper.GetNameFieldByName(dataNPC.NameObject); string fieldOld = Helper.GetNameFieldPosit(oldPosition.x, oldPosition.y); string fieldNew = Helper.GetNameFieldPosit(newPosition.x, newPosition.y); if (fieldOld_Name != fieldOld) { Debug.Log("###### ActionMove = Field not correct " + fieldOld_Name + " <> " + fieldOld + " >>> " + dataNPC.NameObject); fieldOld = fieldOld_Name; } if (!dataNPC.IsReality) { if (dataNPC.IsMoveValid())//FIX~~TRANSFER { dataNPC.StartTransfer("ActionMove"); if (fieldOld != fieldNew) // 2* - test { Storage.Person.UpdateGamePositionInDream(fieldOld, fieldNew, dataNPC, newPosition); } else { //dataNPC.SetPosition(newPosition, isTestValid: false); // 2* dataNPC.SetPosition(newPosition); } dataNPC.StopTransfer(); } } }
public static List <NameActionsPerson> GetActions(ModelNPC.PersonData dataNPC) { var ListPersonActions = new List <NameActionsPerson>(); if (dataNPC.PersonActions == null) { dataNPC.PersonActions = new string[] { } } ; for (int i = 0; i < dataNPC.PersonActions.Length; i++) { NameActionsPerson nextActon = (NameActionsPerson)Enum.Parse(typeof(NameActionsPerson), dataNPC.PersonActions[i].ToString());; ListPersonActions.Add(nextActon); } return(ListPersonActions); }
public static void ActionTargetBackToBase(ModelNPC.PersonData dataNPC, GameActionPersonController controller) { GetAlienData(dataNPC).OnTargetCompleted(); if (controller != null) { //dataNPC.TargetID = controller.TempLockedTargetID; GetAlienData(dataNPC).ReturnBaseTarget(); //GetAlienData(dataNPC).BaseLockedTargetID GetAlienData(dataNPC).BaseLockedTargetID = string.Empty; } RequestActionNPC(dataNPC, NameActionsPerson.Move, controller); if (controller != null) { controller.DrawRayTarget(); //TEST } }
public void ViewPerson(ModelNPC.PersonData dataNPC, GameActionPersonController.NameActionsPerson p_nameAction) { if (dataNPC.IsReality) { return; } m_collectionPersonData.Enqueue(new SceneDialogPerson() { NameAction = p_nameAction, Position = dataNPC.Position, TargetPosition = dataNPC.TargetPosition, NameObject = dataNPC.NameObject }); if (m_collectionPersonData.Count > m_maxPoolDialogs) { m_collectionPersonData.Dequeue(); } }
public static void RequestActionNPC(ModelNPC.PersonData dataNPC, NameActionsPerson p_nameAction, GameActionPersonController controller, bool isForce = false) { if (isForce) { controller.ResetAction(); } if (p_nameAction != NameActionsPerson.Completed) { AddActionNPC(dataNPC, p_nameAction); } if (controller != null) { controller.ActionPerson = NameActionsPerson.Completed; } dataNPC.CurrentAction = NameActionsPerson.Completed.ToString(); }
public static void AddActionNPC(ModelNPC.PersonData dataNPC, NameActionsPerson p_nameAction = NameActionsPerson.None) { var listPersonActions = GetActions(dataNPC); if (listPersonActions.Count() > LimitListCommandActions) { return; } if (listPersonActions.Count > 0) { var lastAction = listPersonActions[listPersonActions.Count - 1]; if (lastAction == p_nameAction) // repeat { return; } } listPersonActions.Add(p_nameAction); dataNPC.PersonActions = listPersonActions.Select(p => p.ToString()).ToArray(); }
public virtual void UpdateData(string callFunc) { _dataNPC = GetUpdateData(callFunc); objID = Helper.GetID(this.name); }
private bool ResavePositionData <T>() where T : ModelNPC.GameDataNPC { if (!_dataNPC.IsReality) { _dataNPC.IsReality = true; Debug.Log(Storage.EventsUI.ListLogAdd = "### CheckComplitionMoveInDream dataNPC IsReality !!!"); } if (Storage.Instance.IsCorrectData) { Debug.Log("_______________ResavePositionData RETURN CorrectData ON CORRECT_______________"); return(true); } if (!string.IsNullOrEmpty(_resName) && _resName != this.gameObject.name) { Debug.Log("################## ERROR MoveObjectToPosition ===========PRED========= rael name: " + this.gameObject.name + " new name: " + _resName); return(true); } if (Storage.Data.IsUpdatingLocationPersonGlobal) { //#test if (!PoolGameObjects.IsUsePoolObjects) { Debug.Log("_______________ResavePositionData RETURN IsUpdatingLocationPerson________ ASYNC _______" + this.gameObject.name); } //return true; } string oldName = this.gameObject.name; Vector3 oldPoint = new Vector3(this.transform.position.x, this.transform.position.y, this.transform.position.z); _resName = _dataNPC.NextPosition(this.gameObject); if (_resName == "Update") { UpdateData("ResavePositionData"); _resName = ""; return(true); } if (_resName == "Error") { return(false); } if (!string.IsNullOrEmpty(_resName)) { if (oldName != _resName) { string callInfo = "ResavePositionData >> oldName(" + oldName + ") != _resName(" + _resName + ")"; _dataNPC = GetUpdateData(callInfo); if (_dataNPC == null) { Debug.Log("################## ERROR MoveObjectToPosition dataNPC is Empty GO:" + this.gameObject.name); return(false); } //TRACK ME if (m_isTrack) { //Debug.Log("m_TrackPoints : " + m_TrackPoints.Count + " " + oldPoint.x + "x" + oldPoint.y); m_TrackPoints.Add(oldPoint); CrateNavigatorTrackPoints(); } } if (_resName != this.gameObject.name) { Debug.Log("################## ERROR MoveObjectToPosition ===========POST========= rael name: " + this.gameObject.name + " new name: " + _resName); this.gameObject.name = _resName; } } return(true); //+++++++++++++++++++++++ }
protected IEnumerator MoveObjectToPosition <T>() where T : ModelNPC.GameDataNPC { float timeLockOnTarget = 0f; //int countLockOnTarget = 0; int speed = 1; Vector2 veloccityStart = _rb2d.velocity; float step = 0; if (!Helper.IsDataInit(this.gameObject)) { isRunning = false; Debug.Log("##################### STOP >>>>>>>>>>>>>>>>>>>>>"); yield break; } string info = "MoveObjectToPosition Init"; _dataNPC = GetUpdateData(); if (_dataNPC != null) { speed = _dataNPC.SpeedCurrent = _dataNPC.Speed; step = speed * Time.deltaTime; } else { Debug.Log("############# MoveObjectToPosition Not FIND dataNPC " + this.gameObject.name + " tag:" + this.gameObject.tag); } bool actionIsMove = true; while (true) { actionIsMove = true; if (_dataNPC != null && _dataNPC.CurrentAction != GameActionPersonController.NameActionsPerson.Move.ToString()) { actionIsMove = false; } if (m_isPause) { actionIsMove = false; } if (actionIsMove) { isRunning = true; if (step == 0) //TEST { step = speed * Time.deltaTime; //!FIX MOVE TARGET! //step = _dataNPC.SpeedCurrent * Time.deltaTime; Storage.EventsUI.ListLogAdd = "Movement NPC step is zero!!!"; } if (Storage.Instance.IsLoadingWorld) { Debug.Log("_______________ LOADING WORLD ....._______________"); yield return(null); } if (Storage.Instance.IsCorrectData) { Debug.Log("_______________ RETURN CorrectData ON CORRECT_______________"); yield return(null); } if (_dataNPC == null) { Debug.Log("########################## UFO MoveObjectToPosition dataUfo is EMPTY"); //Storage.Fix.CorrectData(null, this.gameObject, "MoveObjectToPosition"); UpdateData("MoveObjectToPosition"); isRunning = false; yield break; } //---------------TEST //FIX@@DUBLICATE //if (_dataNPC.NameObject != gameObject.name) //{ // Debug.Log(Storage.EventsUI.ListLogAdd = "#### MoveObjectToPosition ERROR Name " + _dataNPC.NameObject + " <> GO:" + gameObject.name); //} //------------------------------- //isRunning = true; if (_dataNPC.IsMoveValid()) { Vector3 targetPosition = _dataNPC.TargetPosition; _dataNPC.StartTransfer("MoveObjectToPosition"); //FIX~~TRANSFER //float stepMove = step; Vector3 pos = Vector3.MoveTowards(transform.position, targetPosition, step); //---- float distField = Vector2.Distance(new Vector2(targetPosition.x, targetPosition.y) , new Vector2(transform.position.x, transform.position.y)); //!FIX MOVE TARGET! if (distField < 0.5) { if (timeLockOnTarget < Time.time) { timeLockOnTarget = Time.time + 0.5f; if (targetPosition.x > transform.position.x) { pos.x = transform.position.x + step / 2; } else { pos.x = transform.position.x - step / 2; } if (targetPosition.y > transform.position.y) { pos.y = transform.position.y + step / 2; } else { pos.y = transform.position.y - step / 2; } } } //----- if (_rb2d != null) { _rb2d.MovePosition(pos); } else { //Debug.Log("NPC MoveObjectToPosition Set position 2 original........"); transform.position = pos; } //+++++++++++ RESAVE Next Position ++++++++++++ bool res = ResavePositionData <T>(); if (_dataNPC != null) { _dataNPC.StopTransfer(); } if (!res) { Debug.Log("########### STOP MOVE ON ERROR MOVE"); Destroy(this.gameObject); isRunning = false; yield break; } } } yield return(null); isRunning = false; } Debug.Log("##################### STOP >>>>>>>>>>>>>>>>>>>>>"); isRunning = false; }
public static void StartActionNPC(ModelNPC.PersonData dataNPC, NameActionsPerson p_nameAction, GameActionPersonController controller) { if (p_nameAction != NameActionsPerson.None) { if (controller != null) { controller.SetAction(p_nameAction); } } if (controller != null) { dataNPC.CurrentAction = controller.ActionPerson.ToString(); } else { dataNPC.CurrentAction = p_nameAction.ToString(); } switch (p_nameAction) { case NameActionsPerson.Idle: ActionIdle(dataNPC, controller); break; case NameActionsPerson.IdleLock: ActionIdleLock(dataNPC, controller); break; case NameActionsPerson.Move: if (controller == null) { ActionMove(dataNPC); } break; case NameActionsPerson.Completed: ActionTarget(dataNPC, controller); break; case NameActionsPerson.Dead: break; case NameActionsPerson.Attack: break; case NameActionsPerson.Work: ActionWork(dataNPC, controller); break; case NameActionsPerson.Target: ActionTarget(dataNPC, controller); break; case NameActionsPerson.TargetLocal: ActionTargetLocal(dataNPC, controller); break; case NameActionsPerson.TargetBackToBase: ActionTargetBackToBase(dataNPC, controller); break; } //Debug if (controller == null || Storage.SceneDebug.SettingsScene.RealDebugOn || Storage.SceneDebug.VipID == dataNPC.Id) { Storage.SceneDebug.ViewPerson(dataNPC, p_nameAction); } }
public static ModelNPC.GameDataAlien GetAlienData(ModelNPC.PersonData dataNPC) { return(dataNPC as ModelNPC.GameDataAlien); }
public static void ActionTarget(ModelNPC.PersonData dataNPC, GameActionPersonController controller) { if (ActionTargetIsLock) { Debug.Log(Storage.EventsUI.ListLogAdd = ".....ActionTarget is LOCK"); return; } ActionTargetIsLock = true; //Storage.EventsUI.ListLogAdd = "ActionTarget .... ReaderSceneIsValid=" + Storage.Instance.ReaderSceneIsValid; temp_job = null; if (!Storage.Instance.ReaderSceneIsValid)// && TimeEndCurrentAction < Time.time) { ActionTargetLocal(dataNPC, controller); ActionTargetIsLock = false; return; } Storage.EventsUI.ListLogAdd = "ActionTarget ....!!!"; //string tempID = dataNPC.TargetID; string indErr = "0"; try { indErr = "1"; GetAlienData(dataNPC).OnTargetCompleted(); indErr = "2"; //m_TargetObject = Storage.Person.GetAlienNextTargetObject(GetAlienData(dataNPC)); m_TargetObject = null; //@JOB@ temp_job = dataNPC.Job; //Storage.Person.GetAlienNextTargetObject(ref m_TargetObject, ref temp_job, GetAlienData(dataNPC)); AlienJobsManager.GetAlienNextTargetObject(ref m_TargetObject, ref temp_job, GetAlienData(dataNPC)); } catch (Exception ex) { Storage.EventsUI.ListLogAdd = "##### ActionTarget " + ex.Message; ActionTargetIsLock = false; return; } //test if (m_TargetObject == null) { Storage.EventsUI.ListLogAdd = "*** " + dataNPC.NameObject + " ==> empty"; } else { Storage.EventsUI.ListLogAdd = "*** " + dataNPC.NameObject + " ==> " + m_TargetObject.NameObject; } if (m_TargetObject == null) { GetAlienData(dataNPC).SetTargetPosition(); } else { var targetPosition = m_TargetObject.Position; dataNPC.TargetID = m_TargetObject.Id; //FIX base>>ToPortal (dataNPC as ModelNPC.GameDataAlien).BaseLockedTargetID = dataNPC.TargetID; dataNPC.SetTargetPosition(targetPosition); dataNPC.Job = temp_job;//@JOB@ } ExecuteActionNPC(dataNPC, NameActionsPerson.Move, controller); if (controller != null) { controller.DrawRayTarget(); //TEST } ActionTargetIsLock = false; }