/// <summary> /// Change state from current state to new state based on state type /// </summary> /// <param name="newStateType">State to which we want to transition to</param> public override void ChangeState(CharacterStateType newStateType) { ICharacterState newState; //Get the new state from state type dictionary mapping if (possibleStates.TryGetValue(newStateType, out newState)) { //Current state now becomes previous state previousState = currentState; previousStateType = currentStateType; //Exit current state if (currentState != null) { currentState.Exit(); LogState("Exit"); } //Transition to new state currentState = newState; currentStateType = newStateType; //Enter new state currentState.Entry(controller); LogState("Entry"); } else { LogStateError(newStateType + "=> Not a valid state"); } }
public static bool StateActionMacro(Character owner, CharacterStateType currentOrder = CharacterStateType.E_Idle) { string ownerName = owner is Player?owner.GetType().Name : ((Monster)owner).SystemName; int order = CharacterState.CharacterStateActionOrder.FindIndex((s) => s == currentOrder); order = order < 0 ? CharacterState.CharacterStateActionOrder.Count : order; for (int i = 0; i < order; ++i) { CharacterStateType curType = CharacterState.CharacterStateActionOrder[i]; if (owner.Status.CurrentStates.Contains(curType)) { if (CharacterState.IsCharacterStatePlayingAction[curType]) { ChangeAction(owner, ownerName + CharacterState.CharacterStateActionName[curType]); return(true); } else { return(false); } } } return(false); }
public AnimationAction(CharacterStateType eType, bool replaceSame, bool repeat, bool stopAtEnd) { m_eType = eType; m_bReplaceSame = replaceSame; m_bRepeat = repeat; m_bStopAtEnd = stopAtEnd; }
public CharacterState(CharacterStateType type, Character owner, float lifeTime = -1f) { Status = owner.Status; Owner = owner; StateType = type; StateLifeTime = lifeTime; ElapsedTime = 0f; }
public void Init(CharacterStateType state) { m_animationName = "11111"; m_totFrame = 12; m_stateType = state; m_oldStateType = state; m_attackDatas.Clear(); m_attackBmDatas.Clear(); m_attackNmDatas.Clear(); }
public CharacterStateType ChangeByState(CharacterEditorStateData dt, CharacterStateType state) { if (IsStateExist(state) || state == CharacterStateType.ENTER_SCENE || state == CharacterStateType.UNDEFINE) { //Debug.Log("error state or exist state"); return(dt.m_oldStateType); } dt.Init(state); return(state); }
public int GetIndexByState(CharacterStateType stateType) { for (int index = 0; index < m_lsStates.Count; ++index) { if (m_lsStates[index].m_oldStateType == stateType) { return(index); } } return(-1); }
public bool IsStateExist(CharacterStateType stateType) { foreach (CharacterEditorStateData stateData in m_lsStates) { if (stateData.m_stateType == stateType) { return(true); } } return(false); }
public void AddNewState(CharacterStateType state) { if (IsStateExist(state)) { return; } CharacterEditorStateData dt = new CharacterEditorStateData(); dt.Init(state); m_lsStates.Add(dt); }
public static bool StateFinishActionMacro(Character owner, CharacterStateType currentOrder) { string ownerName = owner is Player?owner.GetType().Name : ((Monster)owner).SystemName; if (!owner.Status.CurrentStates.Contains(currentOrder)) { ChangeAction(owner, ownerName + "IdleAction"); return(true); } return(false); }
public void DoAction(CharacterStateType eType) { AnimationAction pAction = m_dicActions[eType]; if (m_pCurrentAction.CanReplace(pAction)) { m_pCurrentAction = pAction; m_pInfo.m_pCurrentStateData = m_pInfo.m_pInstructionData.Actions[eType]; m_pInfo.m_eCurrentStateType = eType; m_pInfo.m_iCurrentFrame = 0; } m_bIsPlaying = true; }
public void RemoveState(CharacterStateType stateKey) { if (State.ContainsKey(stateKey) == true) { State.Remove(stateKey); /** * if (TableTopCharacter != null) * { * TableTopCharacter.RemoveState((AnimatableCharacterStateType)stateKey); * } **/ } }
public override void FromXml(XmlElement xml) { XmlRead.Attr(xml, "id", ref id); XmlRead.Attr(xml, "default_name", ref default_name); XmlRead.Attr(xml, "description", ref description); XmlRead.Attr(xml, "resource_id", ref resource_id); XmlRead.Attr(xml, "scale", ref scale); XmlRead.Attr(xml, "walk_speed_x", ref walk_speed_x); XmlRead.Attr(xml, "walk_speed_y", ref walk_speed_y); XmlRead.Attr(xml, "low_fire_angle", ref low_fire_angle); XmlRead.Attr(xml, "high_fire_angle", ref high_fire_angle); XmlRead.Attr(xml, "fire_range", ref fire_range); int weapon_pos_x = 0; XmlRead.Attr(xml, "weapon_pos_x", ref weapon_pos_x); int weapon_pos_y = 0; XmlRead.Attr(xml, "weapon_pos_y", ref weapon_pos_y); WeaponPosition = new Vector2(weapon_pos_x, weapon_pos_y); XmlRead.Attr(xml, "be_attack_box_min_x", ref be_attack_box_min_x); XmlRead.Attr(xml, "be_attack_box_min_y", ref be_attack_box_min_y); XmlRead.Attr(xml, "be_attack_box_max_x", ref be_attack_box_max_x); XmlRead.Attr(xml, "be_attack_box_max_y", ref be_attack_box_max_y); XmlRead.Attr(xml, "self_skill", ref self_skill); XmlRead.Attr(xml, "m_iHP", ref m_iHP); XmlRead.Attr(xml, "m_iMoveEnergy", ref m_iMoveEnergy); XmlRead.Attr(xml, "m_iAddEnergy", ref m_iAddEnergy); XmlNodeList xmlList = xml.GetElementsByTagName("state"); foreach (XmlNode node in xmlList) { XmlElement ele = node as XmlElement; CharacterStateData pData = DataBase.CreateInstance <CharacterStateData>(); pData.FromXml(ele); CharacterStateType eType = CharacterStateType.UNDEFINE; XmlRead.AttrEnum <CharacterStateType>(ele, "state_type", ref eType); if (Actions.ContainsKey(eType)) { LOG.Error("repeat state[" + eType.ToString() + "] in same instruction[" + id + "]"); } else { Actions[eType] = pData; } } }
/// <summary> /// Initializes Cat FSM with ab inital state /// </summary> /// <param name="initalStateType">Begin from this state</param> public override void InitializeFSM(CharacterStateType initalStateType) { //Map all states FillPossibleStates(); //Assign initial state if (possibleStates.TryGetValue(initalStateType, out currentState)) { currentStateType = initalStateType; LogState("Initialized"); currentState.Entry(controller); LogState("Entry"); } else { LogStateError(initalStateType + "=> Not a valid state"); } }
public HeroCharacterState AddState(CharacterStateType stateKey, bool renderImmediately = true) { HeroCharacterState state; if (State.ContainsKey(stateKey) == false) { state = new HeroCharacterState(this, stateKey); State.Add(stateKey, state); /** * if (TableTopCharacter != null) * { * TableTopCharacter.AddState((AnimatableCharacterStateType)stateKey, renderImmediately); * } **/ } else { state = State[stateKey]; } return(state); }
public void UnInitialize() { m_iHP = 0; m_iFireAngle = 0; m_iCurrentAngle = 0; m_pCurrentStateData = null; m_pInstructionData = null; m_eCurrentStateType = CharacterStateType.UNDEFINE; m_iCurrentFrame = 0; m_iFacing = GameDefine.FACING_RIGHT; m_iDirectionKeys = 0; m_iMoveEnergy = 0; m_iAddEnergy = 0; m_icanattackmin = 0; m_icanattackmax = 0; EmojiID = 0; MessageID = 0; }
public override void ChangeState(CharacterStateType newStateType) { characterFSM.ChangeState(newStateType); }
//Change from current state to new state using State types public abstract void ChangeState(CharacterStateType newStateType);
//Initalize the statemachine with an initial state public abstract void InitializeFSM(CharacterStateType initalState);
public override void OnInspectorGUI() { if (m_chaEditData == null) { PrintLog("the chaEditorData is null"); return; } m_chaEditData.m_id = EditorGUILayout.IntField("PlayerID: ", m_chaEditData.m_id); m_chaEditData.m_resID = EditorGUILayout.IntField("PlayerResourceID:", m_chaEditData.m_resID); m_chaEditData.m_defaultName = EditorGUILayout.TextField("PlayerDefaultName: ", m_chaEditData.m_defaultName); m_chaEditData.m_scale = EditorGUILayout.FloatField("PlayerScale:", m_chaEditData.m_scale); m_chaEditData.m_walkSpeedX = EditorGUILayout.IntField("PlayerXSpeed: ", m_chaEditData.m_walkSpeedX); m_chaEditData.m_walkSpeedY = EditorGUILayout.IntField("PlayerYSpeed:", m_chaEditData.m_walkSpeedY); m_chaEditData.m_hatred = EditorGUILayout.FloatField("PlayerHatred:", m_chaEditData.m_hatred); m_chaEditData.m_lowFireAngle = EditorGUILayout.FloatField("PlayerLowFireAngle:", m_chaEditData.m_lowFireAngle); m_chaEditData.m_higFireAngle = EditorGUILayout.FloatField("PlayerHigFireAngle:", m_chaEditData.m_higFireAngle); m_chaEditData.m_fireRange = EditorGUILayout.IntField("PlayerFireRange:", m_chaEditData.m_fireRange); m_chaEditData.m_weaponPosition = EditorGUILayout.Vector2Field("PlayerWeaponPos", m_chaEditData.m_weaponPosition); m_chaEditData.m_beAttackBoxMinX = EditorGUILayout.IntField("PlayerBAtkBoxMinX:", m_chaEditData.m_beAttackBoxMinX); m_chaEditData.m_beAttackBoxMinY = EditorGUILayout.IntField("PlayerBAtkBoxMinY:", m_chaEditData.m_beAttackBoxMinY); m_chaEditData.m_beAttackBoxMaxX = EditorGUILayout.IntField("PlayerBAtkBoxMaxX:", m_chaEditData.m_beAttackBoxMaxX); m_chaEditData.m_beAttackBoxMaxY = EditorGUILayout.IntField("PlayerBAtkBoxMaxY:", m_chaEditData.m_beAttackBoxMaxY); if (GUILayout.Button("Add New State")) { if (m_chaEditData.IsAllStateExist()) { m_addState = AddState.FULLSTATE; } else { m_addState = AddState.NEWSTATE; } } EditorGUILayout.Space(); if (m_addState == AddState.FULLSTATE) { EditorGUILayout.LabelField("all states is used"); } else if (m_addState == AddState.NEWSTATE) { CharacterStateType newestState = m_chaEditData.GetNewestState(); m_chaEditData.AddNewState(newestState); m_addState = AddState.NONE; } EditorGUILayout.Space(); ///Debug.Log("yes"); for (int index = 0; index < m_chaEditData.m_lsStates.Count; index++) { CharacterEditorData.CharacterEditorStateData chaState = m_chaEditData.m_lsStates[index]; //Debug.Log(EditorGUILayout.EnumPopup("state:", chaState.m_newState)); CharacterStateType state = (CharacterStateType)EditorGUILayout.EnumPopup("state:", chaState.m_stateType); m_chaEditData.ChangeByState(chaState, state); chaState.m_animationName = EditorGUILayout.TextField("AnimationName:", chaState.m_animationName); int totFrame = EditorGUILayout.IntField("TotalFrame:", chaState.m_totFrame); if (totFrame != chaState.m_totFrame) { chaState.m_totFrame = totFrame; chaState.UpdateFramesSz(); } if (chaState.m_stateType == CharacterStateType.ATTACK) { if (GUILayout.Button("Add Frame Data", GUILayout.MaxWidth(130), GUILayout.MaxHeight(20))) { int newFrame = chaState.GetNewFrame(); //Debug.Log(newFrame); if (newFrame != -1) { chaState.AddFrameData(newFrame); } } EditorGUILayout.Space(); for (int i = 0; i < chaState.m_attackDatas.Count; i++) { CharacterEditorData.CharacterEditorAttackData frameData = chaState.m_attackDatas[i]; int frame = EditorGUILayout.IntField("Frame:", frameData.m_iFrame); if (chaState.IsLegalFrame(frame)) { //Debug.Log(frame); frameData.m_iFrame = frame; } CharacterAttackType attackType = (CharacterAttackType)EditorGUILayout.EnumPopup("AttackType:", frameData.m_attackType); chaState.ChangeFrameData(i, attackType); EditorGUILayout.Space(); if (frameData.m_attackType == CharacterAttackType.BOMB) { CharacterEditorData.CharacterEditorBombAttackData bomb = (CharacterEditorData.CharacterEditorBombAttackData)frameData; bomb.m_bombCofigID = EditorGUILayout.IntField("BombConfigID:", bomb.m_bombCofigID); bomb.m_damage = EditorGUILayout.IntField("Damge:", bomb.m_damage); bomb.m_centerDamage = EditorGUILayout.IntField("CenterDamage:", bomb.m_centerDamage); } if (GUILayout.Button("Remove this Frame")) { chaState.RemoveFrameData(frameData.m_iFrame); } EditorGUILayout.Space(); EditorGUILayout.Space(); } } if (GUILayout.Button("remove this state")) { m_chaEditData.RemoveOldState(index); } EditorGUILayout.Space(); EditorGUILayout.Space(); } EditorUtility.SetDirty(m_chaEditData); }
public CharacterAnimiationLogic(CharacterInfo info) { m_pInfo = info; m_pCurrentAction = m_dicActions[CharacterStateType.UNDEFINE]; m_pDefaultActionType = CharacterStateType.IDLE; }
public HeroCharacterState(HeroSystemCharacter character, CharacterStateType stateType) { Type = stateType; Character = character; }