private AvatarAction GetActionByType(int weaponType, int actionType, int rand) { AvatarAction actionCfg = null; // Get action by combat stage from the higher priority to lower priority for (int i = combatStates.Count - 1; i >= 0; i--) { actionCfg = GetRandomAction(weaponType, combatStates[i], actionType, rand); if (actionCfg == null) { actionCfg = GetRandomAction(EquipmentConfig._WeaponType.Empty, combatStates[i], actionType, rand); } if (actionCfg != null) { return(actionCfg); } } actionCfg = GetRandomAction(weaponType, _CombatStateType.Default, actionType, rand); if (actionCfg == null) { actionCfg = GetRandomAction(EquipmentConfig._WeaponType.Empty, _CombatStateType.Default, actionType, rand); } // Can not find the action for the specific state, try to use default state action instead. return(actionCfg); }
public PlayerAvatarAction(PlayerIDFlag playerID, AvatarActionType type, AvatarAction action) { PlayerID = playerID; ActionType = type; Action = action; Target = null; }
public static List <AvatarAction> BuildActions(Dictionary <string, List <SpriteAnimationClip> > actionDictionary) { List <AvatarAction> actions = new List <AvatarAction>(); foreach (KeyValuePair <string, List <SpriteAnimationClip> > kvp in actionDictionary) { string actionName = kvp.Key; List <SpriteAnimationClip> clips = kvp.Value; clips.Sort( delegate(SpriteAnimationClip s1, SpriteAnimationClip s2) { return(s1.angle.CompareTo(s2.angle)); } ); AvatarAction action = ScriptableObject.CreateInstance <AvatarAction>(); action.action = actionName; action.clips = clips.ToArray(); action.deltaAngle = deltaAngle; action.offsetAngle = offsetAngle; action.frameTime = frameTime; string path = AvatarActionPath + "/" + typeName + "/" + unitName + ".asset"; CheckPath(path); AssetDatabase.CreateAsset(action, path); AssetDatabase.SaveAssets(); actions.Add(action); } return(actions); }
public void SetToAction(AvatarAction Action) { buttonType = ActionButtonType.Action; name = Action.ToString(); Data = Action; numOfSameName = 0; }
public static void LinkTypes() { if (gActionTypes.Count == 0) { List <string> avatarActionTypeNames = new List <string>(); avatarActionTypeNames.AddRange(Enum.GetNames(typeof(AvatarActionType))); List <string> avatarActionNames = new List <string>(); avatarActionNames.AddRange(Enum.GetNames(typeof(AvatarAction))); foreach (string avatarActionName in avatarActionNames) { foreach (string avatarActionTypeName in avatarActionTypeNames) { if (avatarActionName.Contains(avatarActionTypeName)) { AvatarAction action = (AvatarAction)Enum.Parse(typeof(AvatarAction), avatarActionName); AvatarActionType actionType = (AvatarActionType)Enum.Parse(typeof(AvatarActionType), avatarActionTypeName); gActionTypes.Add(action, actionType); ////Debug.Log ("paired " + avatarActionName + " with " + avatarActionTypeName); break; } } } } }
public PlayerAvatarAction(PlayerIDFlag playerID, AvatarActionType type, AvatarAction action, GameObject target) { PlayerID = playerID; ActionType = type; Action = action; Target = target; }
public void SetToAction(AvatarAction Action) { RemoveListener(); buttonType = ActionButtonType.Action; name = Action.ToString(); numOfSameName = 0; Data = Action; }
public void PlayActionByType(int actionType) { // Play default combat idle. AvatarAction idleAction = GetActionByType(actionType); if (idleAction != null) { base.PlayAction(idleAction.id); } }
//TODO: THINK ABOUT INPUTS SOME MORE!!! //Java version uses KeyMasks to store AvatarActions between updates, and classes like FlakAvatar exploits that. //Something about limiting the actions up front, instead of after the fact feels better to me. /** * This update call is for the game tick() loop. * @param game current state of the game. */ public virtual void updateAvatar(VGDLGame game, bool requestInput, List <VGDLAvatarActions> actionMask = null) { lastMovementType = VGDLMovementTypes.STILL; var direction = VGDLUtils.VGDLDirections.NONE.getDirection(); if (requestInput || actionMask == null) { //Get the input from the player. VGDLAvatarActions action; if (player != null && player.isHuman) { if (inputHandler.ProcessEscapeInput(playerID)) { game.Abort(); action = VGDLAvatarActions.ACTION_ESCAPE; } //TODO: CHECK IF actions INCLUDE USE KEY! else if (inputHandler.ProcessUseInput(playerID)) { //NOTE: technically we could allow directional input + use action = VGDLAvatarActions.ACTION_USE; } else { //TODO: CHECK IF actions INCLUDE DIRECTIONS! direction = inputHandler.ProcessPlayerMovement(playerID, true); //NOTE: For now we don't handle multiple actions at once, so this is okay. //But if/when that happens, the AvatarActions need to deal with that. action = AvatarAction.fromVector(direction); } player.logAction(action); game.avatarLastAction[playerID] = action; } else { if (player == null) { Debug.LogError("No player attached to avatar: " + getType()); return; } action = requestAgentInput(game); direction = action.getDirection(); } } else { direction = inputHandler.ProcessPlayerInput(actionMask); } //Apply the physical movement. applyMovement(game, direction); }
public virtual void PreLoadAnimation(int actionId) { AvatarAction action = ConfigDatabase.DefaultCfg.ActionConfig.GetActionById(actionId); if (action == null) { return; } Avatar.PreLoadAnimation(action.GetAnimationName(avatarAssetId)); }
public PlayerAvatarAction(AvatarAction action) { PlayerID = PlayerIDFlag.Local; if (!gActionTypes.TryGetValue(action, out ActionType)) { ActionType = AvatarActionType.NoAction; //Debug.Log ("Action " + action + " had no pair"); } Action = action; Target = null; }
/// <summary> /// Returns an AvatarAction from a string. /// </summary> /// <returns></returns> public static AvatarAction GetAction(string Name) { AvatarAction action = AvatarAction.None; string lower = Name.ToLower(); if (String.Equals(lower, AvatarAction.Attack.ToString().ToLower())) { action = AvatarAction.Attack; } else if (String.Equals(lower, AvatarAction.Dance.ToString().ToLower())) { action = AvatarAction.Dance; } else if (String.Equals(lower, AvatarAction.Loot.ToString().ToLower())) { action = AvatarAction.Loot; } else if (String.Equals(lower, AvatarAction.Point.ToString().ToLower())) { action = AvatarAction.Point; } else if (String.Equals(lower, AvatarAction.Rest.ToString().ToLower())) { action = AvatarAction.Rest; } else if (String.Equals(lower, AvatarAction.Buy.ToString().ToLower())) { action = AvatarAction.Buy; } else if (String.Equals(lower, AvatarAction.Inspect.ToString().ToLower())) { action = AvatarAction.Inspect; } else if (String.Equals(lower, AvatarAction.Trade.ToString().ToLower())) { action = AvatarAction.Trade; } else if (String.Equals(lower, AvatarAction.Activate.ToString().ToLower())) { action = AvatarAction.Activate; } else if (String.Equals(lower, AvatarAction.GuildInvite.ToString().ToLower())) { action = AvatarAction.GuildInvite; } else { action = AvatarAction.Wave; } return(action); }
public virtual bool PlayAction(int actionId, bool replayActionId = false) { if (Avatar != null && Avatar.AvatarAnimation != null && Avatar.AvatarAnimation.PlayingAnimation != null && Avatar.AvatarAnimation.PlayingAnimation.animationName.Contains("Die")) { return(false); } // Stop last action. if (replayActionId == false && curActID == actionId) { return(true); } StopAction(); // Play the animation of this action. AvatarAction action = ConfigDatabase.DefaultCfg.ActionConfig.GetActionById(actionId); if (action == null) { return(false); } if (action.GetAnimationName(avatarAssetId) == "") { Debug.LogError(string.Format("Animation name is empty in action({0})", action.id.ToString("X8"))); return(false); } if (!Avatar.PlayAnim(action.GetAnimationName(avatarAssetId))) { return(false); } // Set animation finish callback. Avatar.SetAnimationFinishDeletage(OnAnimationFinished, null, null); // Save the current action ID. curActID = actionId; // Log action. if (LogAction) { LogMsg(String.Format("PlayAction actionId:{0:X} actType:{1:X} animation:{2}", actionId, AvatarAction._Type.GetNameByType(action.actionType), action.GetAnimationName(avatarAssetId))); } return(true); }
public override VGDLAvatarActions act(StateObservationMulti stateObs, ElapsedCpuTimer elapsedTimer) { //int id = (getPlayerID() + 1) % stateObs.getNoPlayers(); var keyhandler = stateObs.getKeyHandler(PlayerID); var move = keyhandler.ProcessPlayerMovement(PlayerID); var useOn = keyhandler.ProcessUseInput(PlayerID); //In the keycontroller, move has preference. VGDLAvatarActions action = AvatarAction.fromVector(move); if (action == VGDLAvatarActions.ACTION_NIL && useOn) { action = VGDLAvatarActions.ACTION_USE; } return(action); }
public override VGDLAvatarActions act(StateObservation stateObs, ElapsedCpuTimer elapsedTimer) { var keyhandler = stateObs.getKeyHandler(0); var move = keyhandler.ProcessPlayerMovement(0); var useOn = keyhandler.ProcessUseInput(0); //In the keycontroller, move has preference. var action = AvatarAction.fromVector(move); //if(action == Types.ACTIONS.ACTION_NIL && useOn) if (useOn) //This allows switching to Use when moving. { action = VGDLAvatarActions.ACTION_USE; } return(action); }
/// <summary> /// 非战斗中使用 /// </summary> public void PlayAnimationByActionType(int actionType, int weaponType, int combatStateType) { int actionCount = ConfigDatabase.DefaultCfg.ActionConfig.GetActionCountInType(weaponType, combatStateType, actionType); if (actionCount == 0) { AvatarAnimation.PlayDefaultAnim(AvatarAssetConfig.ComponentIdToAvatarTypeId(AvatarAssetId)); return; } AvatarAction animAction = ConfigDatabase.DefaultCfg.ActionConfig.GetActionInTypeByIndex(weaponType, combatStateType, actionType, 0); if (animAction.GetAnimationName(AvatarAssetId) == "") { Debug.LogError(string.Format("Animation name is empty in action({0})", animAction.id.ToString("X"))); return; } PlayAnim(animAction.GetAnimationName(AvatarAssetId)); }
/// <summary> /// Rewrites actions from this AvatarControls with actions from given AvatarControls with lower priority value. /// </summary> /// <param name="actions"></param> public void Update(IAvatarControls actions) { if (actions == null) return; DesiredForwardSpeed = actions.DesiredForwardSpeed; DesiredRightSpeed = actions.DesiredRightSpeed; DesiredLeftRotation = actions.DesiredLeftRotation; Interact = actions.Interact; Use = actions.Use; PickUp = actions.PickUp; Fof = actions.Fof; }
/// <summary> /// /// </summary> /// <param name="priority"></param> /// <param name="desiredForwardSpeed"></param> /// <param name="desiredRightSpeed"></param> /// <param name="desiredRotation"></param> /// <param name="interact"></param> /// <param name="use"></param> /// <param name="pickUp"></param> /// <param name="fof"></param> public AvatarControls( int priority, float desiredForwardSpeed = 0f, float desiredRightSpeed = 0f, float desiredRotation = 0f, bool interact = false, bool use = false, bool pickUp = false, PointF fof = default(PointF) ) : this() { m_desiredForwardSpeed = new AvatarAction<float>(desiredForwardSpeed, priority); m_desiredRightSpeed = new AvatarAction<float>(desiredRightSpeed, priority); m_desiredLeftRotation = new AvatarAction<float>(desiredRotation, priority); m_interact = new AvatarAction<bool>(interact, priority); m_use = new AvatarAction<bool>(use, priority); m_pickUp = new AvatarAction<bool>(pickUp, priority); m_fof = new AvatarAction<PointF>(fof, priority); }
public AvatarActionEventArgs(AvatarAction AvatarAction) { this.AvatarAction = AvatarAction; }
public bool ReceiveAction(AvatarAction action, double timeStamp) { gAction.Action = action; return(ReceiveAction(gAction, timeStamp)); }
public void Subscribe(AvatarAction action, ActionListener listener) { gAction.Action = action; Subscribe(gAction, listener); }