public override void SendCommand(CharacterCommands command) { switch(command) { case CharacterCommands.Crouch: UpdateState(HumanBodyStates.CrouchWalk); break; case CharacterCommands.ThrowGrenade: UpdateState(HumanBodyStates.StandIdle); break; case CharacterCommands.Throw: UpdateState(HumanBodyStates.StandIdle); break; case CharacterCommands.LeftAttack: UpdateState(HumanBodyStates.StandIdle); break; case CharacterCommands.RightAttack: UpdateState(HumanBodyStates.StandIdle); break; case CharacterCommands.Block: UpdateState(HumanBodyStates.StandIdle); break; case CharacterCommands.Idle: UpdateState(HumanBodyStates.StandIdle); break; } }
public async Task ConfirmCharDel(SocketReaction reaction, IUserMessage msg) { if (reaction.Emote.ToString() == ok) { string id = reaction.UserId + "\\" + data; Player p = Player.Load(id, Player.IgnoreException.All); await p.DeleteFileMongo(); if (p.Area != null && p.Area.name != "Moceoy's Basement") { NPCSystems.NPC revival = NPCSystems.NPC.GenerateNPC(p.level, "Choichoith"); if (revival != null) { revival.inventory.inv.AddRange(p.inventory.inv); NPCSystems.PopulationHandler.Add(p.Area, revival); } } await TryMSGDel(msg); await CharacterCommands.ListCharacters(reaction.User.Value, reaction.Channel); } else if (reaction.Emote.ToString() == cancel) { await TryMSGDel(msg); } }
public override void SendCommand(CharacterCommands command) { switch (command) { case CharacterCommands.GoToPosition: if (this.ParentCharacter.CurrentStance == HumanStances.Sprint) { UpdateState(HumanBodyStates.WalkForward); } else { UpdateState(HumanBodyStates.CrouchWalk); } break; case CharacterCommands.StopCrouch: UpdateState(HumanBodyStates.StandIdle); break; case CharacterCommands.ThrowGrenade: //_aimFreelookAngle = 0; //_noAimFreelookAngle = 0; break; } }
void EatState() { if (chara.FoodList.Count != 0) { CharacterCommands.Eat(chara, chara.FoodList[0]); } }
// Update is called once per frame void Update() { StateSetter(); switch (charaState) { case States.Moving: if (enemy && Vector2.Distance(transform.position, enemy.transform.position) <= chara.Vision && !enemy.IsDead) { CharacterCommands.SetPath(chara, enemy.transform.position); } else if (target) { CharacterCommands.SetPath(chara, target.position); } break; case States.Attacking: AttackState(); break; case States.Eating: EatState(); break; case States.Seeking: SeekState(); break; default: break; } }
public async Task ConfirmSkills(SocketReaction reaction, IUserMessage msg) { if (reaction.Emote.ToString() == ok) { player.health = player.Health(); player.stamina = player.Stamina(); player.SaveFileMongo(); await TryMSGDel(msg); await CharacterCommands.ChooseRace(player, reaction.Channel); } else if (reaction.Emote.ToString() == cancel) { int[] rolls = Utils.JSON <int[]>(data.Split(';')[0]); player.stats.endurance = 0; player.stats.intelligence = 0; player.stats.strength = 0; player.stats.charisma = 0; player.stats.dexterity = 0; player.stats.perception = 0; player.SaveFileMongo(); await TryMSGDel(msg); await CharacterCommands.SetSkills(player, reaction.Channel, 0, rolls, new bool[6]); } }
public override void SendCommand(CharacterCommands command) { if (command == CharacterCommands.AnimationActionDone) { UpdateState(MutantBodyStates.Idle); } }
public override void SendCommand(CharacterCommands command) { switch (command) { case CharacterCommands.Crouch: UpdateState(HumanBodyStates.CrouchWalk); break; case CharacterCommands.ThrowGrenade: UpdateState(HumanBodyStates.StandIdle); break; case CharacterCommands.Throw: UpdateState(HumanBodyStates.StandIdle); break; case CharacterCommands.LeftAttack: UpdateState(HumanBodyStates.StandIdle); break; case CharacterCommands.RightAttack: UpdateState(HumanBodyStates.StandIdle); break; case CharacterCommands.Block: UpdateState(HumanBodyStates.StandIdle); break; case CharacterCommands.Idle: UpdateState(HumanBodyStates.StandIdle); break; } }
public void command(CharacterCommands command, params object[] args) { switch(command) { case CharacterCommands.SetEntityQuery: eq = (IEntityQuery)args[0]; return; case CharacterCommands.Face: System.Console.WriteLine("face"); state = 0; d = (Directions)args[0]; return; case CharacterCommands.Walk: System.Console.WriteLine("walk"); state = 1; if(d == (Directions)args[0]) step = step==0?1:0; else step = 0; d = (Directions)args[0]; counter = 0; break; case CharacterCommands.Stop: System.Console.WriteLine("stop"); state = 0; return; case CharacterCommands.Step: System.Console.WriteLine("step"); state = 2; if(d == (Directions)args[0]) step = (step+1)&1; else step = 0; d = (Directions)args[0]; counter = 0; return; } }
public override void SendCommand (CharacterCommands command) { if(command == CharacterCommands.AnimationActionDone) { UpdateState(MutantBodyStates.Idle); } }
public override void SendCommand(CharacterCommands command) { switch(command) { case CharacterCommands.Idle: UpdateState(MutantBodyStates.Idle); break; } }
public override void SendCommand(CharacterCommands command) { switch (command) { case CharacterCommands.GoToPosition: UpdateState(MutantBodyStates.Move); break; } }
public override void SendCommand(CharacterCommands command) { switch (command) { case CharacterCommands.Idle: UpdateState(MutantBodyStates.Idle); break; } }
public override void SendCommand (CharacterCommands command) { switch(command) { case CharacterCommands.GoToPosition: UpdateState(MutantBodyStates.Move); break; } }
void AttackState() { if (!enemy.IsDead) { CharacterCommands.Attack(chara, enemy); } else { enemy = null; } }
public override void SendCommand(CharacterCommands command) { if (command == CharacterCommands.AnimationActionDone) { UpdateState(HumanBodyStates.StandIdle); if (ParentCharacter.MyAI.BlackBoard.AnimationAction == AnimationActions.ChairSit) { ParentCharacter.MyAnimator.SetBool("IsChairSitting", false); } } }
void SeekState() { CharacterCommands.GetVision(chara, detectable); if (chara.FoundItems.Count > 0) { foreach (Transform item in chara.FoundItems) { if (item.tag == "Weapon" && item.GetComponent <Weapon>().Damage > chara.Weapon.Damage) { target = item; break; } else if (item.tag == "Treasure") { target = item; break; } } if (!target && !chara.FullFoodBag) { List <Transform> foundFood = new List <Transform>(); foreach (Transform item in chara.FoundItems) { if (item.tag == "Food") { foundFood.Add(item); } } target = GetClosest(foundFood); } if (!enemy) { List <Transform> enemyList = new List <Transform>(); foreach (Transform _enemy in chara.FoundItems) { if (_enemy.tag == "Player" && _enemy.GetComponent <CharacterBehaviours>() != chara) { enemyList.Add(_enemy); print(_enemy.name); } } if (enemyList.Count > 1) { GameObject closestEnemy = GetClosest(enemyList).gameObject; enemy = closestEnemy.GetComponent <CharacterBehaviours>(); } else if (enemyList.Count != 0) { enemy = enemyList[0].GetComponent <CharacterBehaviours>(); } } } }
public async Task SetSkill(SocketReaction reaction, IUserMessage msg) { int result = GetLetter(reaction.Emote.ToString()) + 1; string[] arrays = data.Split(';'); bool[] rused = Utils.JSON <bool[]>(arrays[1]); if (!rused[result - 1]) { await CharacterCommands.SetSkills(player, reaction.Channel, result, Utils.JSON <int[]>(arrays[0]), rused, true); } }
Text playerNameText; //Nome do seu personagem private void Start() { if (Weapon == null) { Weapon = Instantiate(Resources.Load <Weapon>("Prefabs/DemFists"), transform.position, Quaternion.identity); CharacterCommands.CatchWeapon(this, Weapon.gameObject); } if (GetComponentInChildren <Canvas>()) { playerNameText = GetComponentInChildren <Text>(); //PlayerNameText é um componente do canvas filho do prefab. Deve ser referenciado dessa maneira para que o nome do seu personagem apareça na tela do jogo playerNameText.text = PlayerName; } }
public async Task ChooseRace(SocketReaction reaction, IUserMessage msg) { bool selected = true; switch (reaction.Emote.ToString()) { case "🇭": { player.race = ReferenceData.HumanoidRaces.Human; player.perks.Add(PerkLoad.Load("Human Adaptation")); } break; case "🇹": { player.race = ReferenceData.HumanoidRaces.Tsiun; player.perks.Add(PerkLoad.Load("Tsiun Trickery")); } break; case "🇺": { player.race = ReferenceData.HumanoidRaces.Uskavian; player.perks.Add(PerkLoad.Load("Uskavian Learning")); } break; case "🇲": { player.race = ReferenceData.HumanoidRaces.Miganan; player.perks.Add(PerkLoad.Load("Migana Skin")); } break; case "🇮": { player.race = ReferenceData.HumanoidRaces.Ireskian; player.perks.Add(PerkLoad.Load("Ireskian Talent")); } break; default: selected = false; break; } if (selected) { player.SaveFileMongo(); await TryMSGDel(msg); await CharacterCommands.StarterAbilities(player, reaction.Channel, 0); } }
public override void SendCommand (CharacterCommands command) { switch(command) { case CharacterCommands.GoToPosition: UpdateState(HumanBodyStates.WalkForward); break; case CharacterCommands.Crouch: UpdateState(HumanBodyStates.CrouchIdle); break; case CharacterCommands.ThrowGrenade: //_aimFreelookAngle = 0; //_noAimFreelookAngle = 0; break; } }
public override void SendCommand(CharacterCommands command) { switch (command) { case CharacterCommands.GoToPosition: UpdateState(HumanBodyStates.WalkForward); break; case CharacterCommands.Crouch: UpdateState(HumanBodyStates.CrouchIdle); break; case CharacterCommands.ThrowGrenade: //_aimFreelookAngle = 0; //_noAimFreelookAngle = 0; break; } }
// Update is called once per frame void Update() { if (chara.IsDead) { return; } if (!target) { CharacterCommands.GetVision(chara, players); } else { if (Vector2.Distance(transform.position, target.transform.position) <= chara.Weapon.Range) { CharacterCommands.Attack(chara, target); } } }
private void OnTriggerEnter2D(Collider2D col) { if (col.transform == target) { if (col.tag == "Food") { CharacterCommands.CatchFood(chara, col.gameObject); } if (col.tag == "Weapon") { CharacterCommands.CatchWeapon(chara, col.gameObject); } if (col.tag == "Treasure") { CharacterCommands.CatchTreasure(chara, col.gameObject); } target = null; } }
public async Task StarterAbilities(SocketReaction reaction, IUserMessage msg) { string[] split = data.Split('/'); int p = int.Parse(split[0]); int x = int.Parse(split[1]); int z = int.Parse(split[2]); int index = GetNum(reaction.Emote.ToString()); if (index > -1) { Ability a = Ability.Load(LoadAbility.Starters[p, index]); if (player.abilities.Count < 3) { player.abilities.Add(a); } if (x > -1) { string prefix = CommandHandler.GetPrefix(reaction.Channel); player.level = 0; await EditMessage("Character creation completed"); await GameCommands.StatsDisplay(player, reaction.Channel); await reaction.Channel.SendMessageAsync("Welcome to Neitsillia, Traveler. To guide you, you've been given the \"Tutorial\" Quest line." + Environment.NewLine + "Use the `Quest` command to view your quest list and inspect the quest using the assigned emote. Follow the Tutorial quest to learn to play."); } else { await CharacterCommands.StarterAbilities(player, reaction.Channel, p); } player.SaveFileMongo(); } else if (reaction.Emote.ToString() == next) { await CharacterCommands.StarterAbilities(player, reaction.Channel, p + 1, x, z); } else if (reaction.Emote.ToString() == prev) { await CharacterCommands.StarterAbilities(player, reaction.Channel, p - 1, x, z); } }
public override void SendCommand(CharacterCommands command) { switch (command) { case CharacterCommands.StopCrouch: Debug.Log("Stop Crouch during sneak forward"); UpdateState(HumanBodyStates.StandIdle); break; case CharacterCommands.Idle: UpdateState(HumanBodyStates.CrouchIdle); break; case CharacterCommands.ThrowGrenade: UpdateState(HumanBodyStates.CrouchIdle); break; case CharacterCommands.Throw: UpdateState(HumanBodyStates.CrouchIdle); break; } }
public void Command(CharacterCommands command, params object[] args) { customAnimation = null; switch(command) { case CharacterCommands.Step: state = 1; d = (Directions)args[0]; walkAnims[(int)d].reset(); return; case CharacterCommands.Face: //if(state == 1 && d == (Directions)args[0]) { } //else //state = 0; if(d != (Directions)args[0]) state = 0; d = (Directions)args[0]; return; case CharacterCommands.Stop: state = 0; return; case CharacterCommands.Walk: if(d == (Directions)args[0] && state == 1) { } else { state = 1; walkAnims[(int)(Directions)args[0]].reset(); d = (Directions)args[0]; } return; case CharacterCommands.Animate: state = 3; customAnimation = new StandardChrAnimationController((string)args[0]); customAnimation.reset(); return; default: return; } }
public override void SendCommand (CharacterCommands command) { switch(command) { case CharacterCommands.GoToPosition: if(this.ParentCharacter.CurrentStance == HumanStances.Sprint) { UpdateState(HumanBodyStates.WalkForward); } else { UpdateState(HumanBodyStates.CrouchWalk); } break; case CharacterCommands.StopCrouch: UpdateState(HumanBodyStates.StandIdle); break; case CharacterCommands.ThrowGrenade: //_aimFreelookAngle = 0; //_noAimFreelookAngle = 0; break; } }
public async Task AutoNewCharacter(SocketReaction reaction, IUserMessage msg) { switch (reaction.Emote.ToString()) { case ok: await CharacterCommands.AutoCharacter(player, reaction.Channel, false); break; case next: await CharacterCommands.SetSkills(player, reaction.Channel, 0, null, new[] { false, false, false, false, false, false }); break; case info: EmbedBuilder em = DUtils.BuildEmbed("Character Creation", $"{EUI.ok} - Randomize {Environment.NewLine} {EUI.next} - Manual (Advanced)", null, default, DUtils.NewField("Use the reactions to make your choice", "Making a character can be complicated for new users, use this to skip this step and start playing." + Environment.NewLine + "You can always make another new character once you are more comfortable with the system.")); await EditMessage(null, em.Build(), removeReactions : false); break; } }
public override void SendCommand (CharacterCommands command) { if(command == CharacterCommands.PlayAnimationAction) { CurrentAnimState = new MutantAnimStateAction(this); IsBodyLocked = true; } if(command == CharacterCommands.AnimationActionDone) { Debug.Log("Action Done"); IsBodyLocked = false; } if(!IsBodyLocked && !IsMoveLocked) { CurrentAnimState.SendCommand(command); } if(IsBodyLocked) { return; } /* if(command == CharacterCommands.IdleAction) { if(UnityEngine.Random.value > 0.5f) { this.MyAnimator.SetTrigger("Agonize"); } else { this.MyAnimator.SetTrigger("Convulse"); } } */ if(command == CharacterCommands.RunningAttack) { this.MyAnimator.SetTrigger("RunningAttack"); MyReference.FixedMeleeRight.GetComponent<MeleeWeapon>().SwingStart(); ActionState = HumanActionStates.Melee; } if(command == CharacterCommands.LeftAttack) { this.MyAnimator.SetTrigger("LeftAttack"); MyReference.FixedMeleeLeft.GetComponent<MeleeWeapon>().SwingStart(); ActionState = HumanActionStates.Melee; } if(command == CharacterCommands.RightAttack) { this.MyAnimator.SetTrigger("RightAttack"); MyReference.FixedMeleeRight.GetComponent<MeleeWeapon>().SwingStart(); ActionState = HumanActionStates.Melee; } if(command == CharacterCommands.QuickAttack) { this.MyAnimator.SetTrigger("QuickAttack"); MyReference.FixedMeleeRight.GetComponent<MeleeWeapon>().SwingStart(); ActionState = HumanActionStates.Melee; } }
public bool supportsCommand(CharacterCommands command) { return true; }
public override void SendCommand (CharacterCommands command) { }
public override void SendCommand(CharacterCommands command) { if (command == CharacterCommands.PlayAnimationAction) { CurrentAnimState = new MutantAnimStateAction(this); IsBodyLocked = true; } if (command == CharacterCommands.AnimationActionDone) { //Debug.Log("Action Done"); IsBodyLocked = false; } if (!IsBodyLocked && !IsMoveLocked) { CurrentAnimState.SendCommand(command); } if (IsBodyLocked) { return; } /* * if(command == CharacterCommands.IdleAction) * { * if(UnityEngine.Random.value > 0.5f) * { * this.MyAnimator.SetTrigger("Agonize"); * } * else * { * this.MyAnimator.SetTrigger("Convulse"); * } * } */ if (command == CharacterCommands.RunningAttack) { this.MyAnimator.SetTrigger("RunningAttack"); _meleeSide = 1; ActionState = HumanActionStates.Melee; } if (command == CharacterCommands.LeftAttack) { this.MyAnimator.SetTrigger("LeftAttack"); _meleeSide = 0; ActionState = HumanActionStates.Melee; } if (command == CharacterCommands.RightAttack) { this.MyAnimator.SetTrigger("RightAttack"); _meleeSide = 1; ActionState = HumanActionStates.Melee; } if (command == CharacterCommands.QuickAttack) { this.MyAnimator.SetTrigger("QuickAttack"); _meleeSide = 1; ActionState = HumanActionStates.Melee; } if (command == CharacterCommands.Bite) { if (ActionState != HumanActionStates.None || MyAI.BlackBoard.TargetEnemy == null) { return; } //Debug.Log("Start biting"); Vector3 lineOfSight = MyAI.BlackBoard.TargetEnemy.transform.position - transform.position; //stop movement SendCommand(CharacterCommands.Idle); IsBodyLocked = true; MyNavAgent.enabled = false; //place my position right behind target transform.position = MyAI.BlackBoard.TargetEnemy.transform.position - lineOfSight.normalized * 1f; //align my facing direction to enemy's lineOfSight = new Vector3(lineOfSight.x, 0, lineOfSight.z); Quaternion rotation = Quaternion.LookRotation(lineOfSight); transform.rotation = rotation; MyAnimator.SetTrigger("Bite"); _strangleTarget = MyAI.BlackBoard.TargetEnemy; ActionState = HumanActionStates.Strangle; } }
internal static async Task <bool> SpecialExceptions(NeitsilliaError error, IMessageChannel chan, Player player) { switch (error.ErrorType) { case NeitsilliaErrorType.ReplyError: await chan.SendMessageAsync(error.ExtraMessage); return(true); case NeitsilliaErrorType.ReplyUI: { await chan.SendMessageAsync(error.ExtraMessage); switch (error.uitype) { case MsgType.CardGame: { Type type = Neitsillia.Gambling.Games.GamblingGame.GetGameType(player.ui.data); Neitsillia.Gambling.Games.IGamblingGame game = Neitsillia.Gambling.Games.GamblingGame.CreateInstance(type, player); var embed = ((Neitsillia.Gambling.Games.GamblingGame)game).GetEmbed(player).Build(); await player.NewUI(null, embed, await player.DMChannel(), player.ui.type, player.ui.data); } break; } return(true); } case NeitsilliaErrorType.CharacterIsNotSetUp: if (player != null) { if (player.ui.type == MsgType.AutoNewCharacter) { await CharacterCommands.AutoCharacter(player, chan, true); } else if (player.ui.type == MsgType.SetSkill || player.ui.type == MsgType.ConfirmSkills) { string[] arrays = player.ui.data.Split(';'); await CharacterCommands.SetSkills(player, chan, 0, Utils.JSON <int[]>(arrays[0]), Utils.JSON <bool[]>(arrays[1])); } else if (!await CharacterCommands.Set_Race(chan, player)) { await CharacterCommands.StarterAbilities(player, chan, 1); } return(true); } return(false); case NeitsilliaErrorType.CharacterAdventuring: if (player != null) { await Areas.AdventureStat(player, chan); return(true); } return(false); case NeitsilliaErrorType.CharacterIsResting: if (player != null) { await Areas.RestStat(player, chan); return(true); } return(false); default: return(false); } }
public abstract void SendCommand(CharacterCommands command);
public abstract bool supportsCommand(CharacterCommands cc);
public override void SendCommand(CharacterCommands command) { }
public override bool supportsCommand(CharacterCommands cc) { return true; }
public abstract void command(CharacterCommands cc, params object[] args);
public override void command(CharacterCommands cc, params object[] args) { }
public override void command(CharacterCommands cc, params object[] args) { switch(cc) { case CharacterCommands.Face: Directions d = (Directions)args[0]; switch(d) { //there are cleverer ways to do this //like take the difference one way and if its greater than pi, invert delta case Directions.e: target = east; if(angle > east && angle < west) delta = -1; else delta = 1; break; case Directions.n: target = north; if(angle > south) delta = 1; else delta = -1; break; case Directions.s: target = south; if(angle < south) delta = 1; else delta = -1; break; case Directions.w: target = west; if(angle < west && angle > east) delta = 1; else delta = -1; break; } break; } }
public override void command(CharacterCommands cc, params object[] args) { switch(cc) { case CharacterCommands.Face: facing = (Directions)args[0]; break; } }
void MoveState(Transform _target) { CharacterCommands.SetPath(chara, _target.position); }
public void Command(CharacterCommands command, params object[] args) { customAnimation = null; switch(command) { case CharacterCommands.Step: state = 1; d = (Directions)args[0]; walkAnims[(int)d].controller.reset(); return; case CharacterCommands.Face: //if(state == 1 && d == (Directions)args[0]) { } //else //state = 0; //if(d != (Directions)args[0]) state = 0; if(d != (Directions)args[0]) { d = (Directions)args[0]; if(GetCurrentAnimRecord() != null) GetCurrentAnimRecord().controller.reset(); } return; case CharacterCommands.Stop: { state = 0; AnimRecord ar = GetCurrentAnimRecord(); if(ar != null) ar.controller.reset(); } return; case CharacterCommands.Walk: if(d == (Directions)args[0] && state == 1) { } else { state = 1; walkAnims[(int)(Directions)args[0]].controller.reset(); d = (Directions)args[0]; } return; case CharacterCommands.Animate: if(animations.TryGetValue((string)args[0], out customAnimation)) { customAnimation.controller.reset(); state = 3; } else state = 0; return; default: return; } }
public bool SupportsCommand(CharacterCommands command) { if(command == CharacterCommands.Step) return false; return true; }
public override void SendCommand(CharacterCommands command) { if(!IsBodyLocked && !IsMoveLocked) { CurrentAnimState.SendCommand(command); } //following commands are not given by AI or user. All commands that will unlock the body go here if(command == CharacterCommands.StopAim) { if(ActionState == HumanActionStates.None) { MyAI.WeaponSystem.StopFiringRangedWeapon(); UpperBodyState = HumanUpperBodyStates.Idle; MyAimIK.solver.SmoothDisable(6); MyHeadIK.SmoothEnable(); MyAnimator.SetBool("IsAiming", false); MyReference.Flashlight.transform.localEulerAngles = new Vector3(27, 0, 0); if(GetCurrentAnimWeapon() == WeaponAnimType.Pistol || GetCurrentAnimWeapon() == WeaponAnimType.Grenade) { MyLeftHandIK.InstantDisable(); } } else { UpperBodyState = HumanUpperBodyStates.Idle; } _isHipAiming = false; //Debug.LogError("stopping aim " + ActionState + " " + this.name); } if(command == CharacterCommands.Cancel) { if(ActionState == HumanActionStates.Strangle) { ActionState = HumanActionStates.None; MyAnimator.SetTrigger("Cancel"); Vector3 lineOfSight = _strangleTarget.transform.position - transform.position; transform.position = _strangleTarget.transform.position - lineOfSight.normalized; if(_strangleTarget.IsAlive) { _strangleTarget.IsBodyLocked = false; _strangleTarget.MyAnimator.SetTrigger("Cancel"); _strangleTarget = null; } IsBodyLocked = false; MyNavAgent.enabled = true; } } if(command == CharacterCommands.RightAttack) { ActionState = HumanActionStates.Melee; _meleeStrikeStage = 0; MyAnimator.SetTrigger("RightAttack"); IsMoveLocked = true; MyHeadIK.SmoothDisable(9); Debug.Log("starting right attack"); } if(command == CharacterCommands.LeftAttack) { ActionState = HumanActionStates.Melee; _meleeStrikeStage = 0; Vector3 lookDir = LookTarget.position - transform.position; lookDir = new Vector3(lookDir.x, 0, lookDir.z); Vector3 destDir = MyNavAgent.velocity.normalized; destDir = new Vector3(destDir.x, 0, destDir.z); float lookDestAngle = Vector3.Angle(lookDir, destDir); if(MyNavAgent.velocity.magnitude > 0f && lookDestAngle < 70) { MyAnimator.SetTrigger("ComboAttack"); } else { MyAnimator.SetTrigger("LeftAttack"); IsMoveLocked = true; } MyHeadIK.SmoothDisable(9); Debug.Log("starting left attack"); } if(command == CharacterCommands.Block) { ActionState = HumanActionStates.Block; this.MyLeftHandIK.Target = MyReference.CurrentWeapon.GetComponent<Weapon>().ForeGrip; this.MyLeftHandIK.SmoothEnable(20); _meleeStrikeStage = 0; MyAnimator.SetTrigger("Block"); IsMoveLocked = true; } if(IsBodyLocked) { return; } //following commands are given by AI or user, and can be locked if(command == CharacterCommands.Crouch) { CapsuleCollider collider = GetComponent<CapsuleCollider>(); collider.height = 1f; collider.center = new Vector3(0, 0.5f, 0); } if(command == CharacterCommands.StopCrouch) { CapsuleCollider collider = GetComponent<CapsuleCollider>(); collider.height = 1.7f; collider.center = new Vector3(0, 1, 0); } if((command == CharacterCommands.Aim || command == CharacterCommands.HipAim) && CurrentStance != HumanStances.Sprint) { if(MyAI.ControlType != AIControlType.Player) Debug.Log("action state " + ActionState + " weapon type " + GetCurrentAnimWeapon() + " upper body state " + UpperBodyState); if((ActionState == HumanActionStates.None || ActionState == HumanActionStates.Twitch) && GetCurrentAnimWeapon() != WeaponAnimType.Unarmed && !MyAnimator.GetBool("IsAiming")) { if(MyAI.ControlType != AIControlType.Player) Debug.Log(command); if(GetCurrentAnimWeapon() == WeaponAnimType.Grenade || GetCurrentAnimWeapon() == WeaponAnimType.Tool) { MyLeftHandIK.SmoothDisable(6); UpperBodyState = HumanUpperBodyStates.HalfAim; } else { UpperBodyState = HumanUpperBodyStates.Aim; if(GetCurrentAnimWeapon() == WeaponAnimType.Pistol) { MyLeftHandIK.InstantDisable(); } MyLeftHandIK.SmoothEnable(6); MyAimIK.solver.InstantDisable(); MyAimIK.solver.CurvedEnable(6f); //if(GetCurrentAnimWeapon() != WeaponAnimType.Melee) { MyHeadIK.InstantDisable(); } MyAnimator.SetBool("IsAiming", true); if(MyAI.ControlType != AIControlType.Player) Debug.LogError("Animation parameter IsAiming has been set"); MyReference.Flashlight.transform.localEulerAngles = new Vector3(0, 0, 0); } /* //draw a new grenade if there isn't one if(GetCurrentAnimWeapon() == WeaponAnimType.Grenade) { if(_thrownObjectInHand == null) { DrawNextGrenade(); } } */ } else if(ActionState == HumanActionStates.SwitchWeapon) { if(UpperBodyState == HumanUpperBodyStates.Aim && !MyAnimator.GetBool("IsAiming")) { MyLeftHandIK.InstantDisable(); MyLeftHandIK.SmoothEnable(6); MyAimIK.solver.InstantDisable(); MyAimIK.solver.SmoothEnable(6f); MyHeadIK.InstantDisable(); MyAnimator.SetBool("IsAiming", true); if(MyAI.ControlType != AIControlType.Player) Debug.LogError("Animation parameter IsAiming has been set"); MyReference.Flashlight.transform.localEulerAngles = new Vector3(0, 0, 0); } else { UpperBodyState = HumanUpperBodyStates.Aim; } } else if(GetCurrentAnimWeapon() == WeaponAnimType.Unarmed) { SendCommand(MyAI.WeaponSystem.GetBestWeaponChoice()); } if(command == CharacterCommands.HipAim) { _isHipAiming = true; } else if(command == CharacterCommands.Aim) { _isHipAiming = false; } } if(command == CharacterCommands.Sprint) { /* if(CurrentStance == HumanStances.Crouch || CurrentStance == HumanStances.CrouchRun) { CurrentStance = HumanStances.CrouchRun; } else*/ { CurrentStance = HumanStances.Sprint; MyAimIK.solver.SmoothDisable(); MyHeadIK.InstantDisable(); } } if(command == CharacterCommands.StopSprint) { if(UpperBodyState == HumanUpperBodyStates.Aim) { MyAimIK.solver.SmoothEnable(); } if(CurrentStance == HumanStances.CrouchRun || CurrentStance == HumanStances.Crouch) { CurrentStance = HumanStances.Crouch; } else { CurrentStance = HumanStances.Run; } MyHeadIK.SmoothEnable(); } if(command == CharacterCommands.SwitchWeapon2) { if((ActionState == HumanActionStates.None || ActionState == HumanActionStates.Twitch) && MyAI.WeaponSystem.PrimaryWeapon != null) { CsDebug.Inst.CharLog(this, "Start switching weapon2"); MyLeftHandIK.SmoothDisable(15); MyAimIK.solver.SmoothDisable(9); //SwitchWeapon(Inventory.RifleSlot); _weaponToSwitch = Inventory.RifleSlot; if(MyAI.WeaponSystem.PrimaryWeapon.IsRanged) { MyAnimator.SetInteger("WeaponType", 2); } else { MyAnimator.SetInteger("WeaponType", 3); } ActionState = HumanActionStates.SwitchWeapon; } } if(command == CharacterCommands.SwitchWeapon1) { if((ActionState == HumanActionStates.None || ActionState == HumanActionStates.Twitch) && MyAI.WeaponSystem.SideArm != null) { if(UpperBodyState == HumanUpperBodyStates.Aim) { //MyLeftHandIK.SmoothEnable(); } else { } MyLeftHandIK.SmoothDisable(15); MyAimIK.solver.SmoothDisable(9); MyAnimator.SetInteger("WeaponType", 1); //SwitchWeapon(Inventory.SideArmSlot); _weaponToSwitch = Inventory.SideArmSlot; ActionState = HumanActionStates.SwitchWeapon; } } if(command == CharacterCommands.SwitchThrown) { if(ActionState == HumanActionStates.None) { MyLeftHandIK.SmoothDisable(6); MyAimIK.solver.SmoothDisable(9); MyAnimator.SetInteger("WeaponType", -1); //SwitchWeapon(Inventory.ThrowSlot); _weaponToSwitch = Inventory.ThrowSlot; ActionState = HumanActionStates.SwitchWeapon; } } if(command == CharacterCommands.SwitchTool) { if(ActionState == HumanActionStates.None) { GameObject.Destroy(this.MyReference.CurrentWeapon); if(_thrownObjectInHand != null) { GameObject.Destroy(_thrownObjectInHand.gameObject); } MyLeftHandIK.SmoothDisable(6); MyAimIK.solver.SmoothDisable(9); MyAnimator.SetInteger("WeaponType", -2); //SwitchWeapon("ThrowingRock"); ActionState = HumanActionStates.SwitchWeapon; } } if(command == CharacterCommands.Unarm) { if(ActionState == HumanActionStates.None) { MyLeftHandIK.SmoothDisable(); UpperBodyState = HumanUpperBodyStates.Idle; MyAimIK.solver.SmoothDisable(); MyHeadIK.SmoothEnable(); MyAnimator.SetBool("IsAiming", false); MyAnimator.SetInteger("WeaponType", 0); //SwitchWeapon(null); _weaponToSwitch = null; ActionState = HumanActionStates.SwitchWeapon; } } if(command == CharacterCommands.PullTrigger) { if(ActionState != HumanActionStates.None || UpperBodyState != HumanUpperBodyStates.Aim) { return; } if(GetCurrentAnimWeapon() == WeaponAnimType.Longgun || GetCurrentAnimWeapon() == WeaponAnimType.Pistol) { // this.MyReference.CurrentWeapon.GetComponent<Gun>().TriggerPull(); } } if(command == CharacterCommands.ReleaseTrigger) { if(ActionState != HumanActionStates.None || UpperBodyState != HumanUpperBodyStates.Aim) { return; } if(GetCurrentAnimWeapon() == WeaponAnimType.Longgun || GetCurrentAnimWeapon() == WeaponAnimType.Pistol) { // this.MyReference.CurrentWeapon.GetComponent<Gun>().TriggerRelease(); } } if(command == CharacterCommands.Reload) { if(ActionState == HumanActionStates.None && this.MyReference.CurrentWeapon != null) { GunMagazine magazine = this.MyReference.CurrentWeapon.GetComponent<GunMagazine>(); if(magazine != null && magazine.AmmoLeft < magazine.MaxCapacity) { GridItemData ammo = this.Inventory.FindItemInBackpack(magazine.LoadedAmmoID); if(ammo != null) { if(GetCurrentAnimWeapon() == WeaponAnimType.Longgun || GetCurrentAnimWeapon() == WeaponAnimType.Pistol) { MyAimIK.solver.SmoothDisable(12); MyAnimator.SetInteger("ReloadType", (int)magazine.ReloadType); MyAnimator.SetTrigger("Reload"); MyLeftHandIK.SmoothDisable(); } MyHeadIK.SmoothDisable(); ActionState = HumanActionStates.Reload; } } } } if(command == CharacterCommands.CancelReload) { if(ActionState == HumanActionStates.Reload && this.MyReference.CurrentWeapon != null) { Debug.Log("cancel reload"); ActionState = HumanActionStates.None; if(UpperBodyState == HumanUpperBodyStates.Aim) { MyAimIK.solver.SmoothEnable(); MyAnimator.SetTrigger("CancelReload"); } else { MyAnimator.SetTrigger("CancelReload"); } if(MyAnimator.GetInteger("WeaponType") == (int)WeaponAnimType.Longgun) { MyLeftHandIK.SmoothEnable(); } else { Debug.Log("done reloading pistol " + UpperBodyState); if(UpperBodyState == HumanUpperBodyStates.Aim) { MyLeftHandIK.SmoothEnable(); } else { //MyLeftHandIK.SmoothDisable(); SendCommand(CharacterCommands.StopAim); } } MyHeadIK.SmoothEnable(); } } if(command == CharacterCommands.Throw || command == CharacterCommands.LowThrow) { if(ActionState != HumanActionStates.None) { return; } if(_thrownObjectInHand == null) { DrawNextGrenade(); } MyAimIK.solver.SmoothDisable(15); if(command == CharacterCommands.LowThrow) { MyAnimator.SetTrigger("LowThrow"); _isLowThrow = true; } else { MyAnimator.SetTrigger("Throw"); _isLowThrow = false; } _throwTarget = this.AimPoint; Quaternion rotation = Quaternion.LookRotation(this.AimPoint - transform.position); transform.rotation = rotation; IsBodyLocked = true; Debug.Log("Throw triggered"); } if(command == CharacterCommands.ThrowGrenade) { if(ActionState != HumanActionStates.None) { return; } if(UpperBodyState != HumanUpperBodyStates.Aim) { //MyAimIK.solver.transform = this.MyReference.TorsoWeaponMount.transform; } SendCommand(CharacterCommands.CancelReload); if(this.MyReference.CurrentWeapon != null && MyAnimator.GetInteger("WeaponType") == (int)WeaponAnimType.Longgun) { MyLeftHandIK.SmoothEnable(); } //MyHeadIK.SmoothDisable(1); //move weapon to torso mount so that right hand is free if(this.MyReference.CurrentWeapon != null) { this.MyReference.CurrentWeapon.transform.parent = this.MyReference.TorsoWeaponMount.transform; } MyAnimator.SetTrigger("ThrowGrenade"); _throwTarget = this.AimPoint; _throwDir = this.AimPoint - transform.position; IsBodyLocked = true; Quaternion rotation = Quaternion.LookRotation(new Vector3(_throwDir.x, 0, _throwDir.z)); transform.rotation = rotation; ActionState = HumanActionStates.Throw; _thrownObjectInHand = ((GameObject)GameObject.Instantiate(Resources.Load("PipeGrenade"))).GetComponent<ThrownObject>(); Explosive explosive = _thrownObjectInHand.GetComponent<Explosive>(); if(explosive != null) { explosive.Attacker = this; } _thrownObjectInHand.GetComponent<Rigidbody>().isKinematic = true; _thrownObjectInHand.transform.parent = this.MyReference.RightHandWeaponMount.transform; _thrownObjectInHand.transform.localPosition = _thrownObjectInHand.InHandPosition; _thrownObjectInHand.transform.localEulerAngles = _thrownObjectInHand.InHandRotation; } if(command == CharacterCommands.UseTool) { if(ActionState != HumanActionStates.None || MyAI.BlackBoard.TargetEnemy == null) { return; } //check if the target enemy is close enough and angle between character and enemy is less than 45 if(Vector3.Distance(MyAI.BlackBoard.TargetEnemy.transform.position, transform.position) > 2 || Vector3.Angle(MyAI.BlackBoard.TargetEnemy.transform.forward, transform.forward) > 45) { return; } Vector3 lineOfSight = MyAI.BlackBoard.TargetEnemy.transform.position - transform.position; //check if angle between character facing and target line of sight is less than 45 if(Vector3.Angle(lineOfSight, transform.forward) > 45) { return; } //stop movement SendCommand(CharacterCommands.Idle); IsBodyLocked = true; MyNavAgent.enabled = false; //place player right behind target transform.position = MyAI.BlackBoard.TargetEnemy.transform.position - lineOfSight.normalized * 0.25f; //align player facing direction to enemy's lineOfSight = new Vector3(lineOfSight.x, 0, lineOfSight.z); Quaternion rotation = Quaternion.LookRotation(lineOfSight); transform.rotation = rotation; MyAnimator.SetTrigger("Strangle"); _strangleTarget = MyAI.BlackBoard.TargetEnemy; SendCommand(CharacterCommands.StopAim); ActionState = HumanActionStates.Strangle; } if(command == CharacterCommands.Pickup) { if(ActionState != HumanActionStates.None || MyAI.BlackBoard.PickupTarget == null) { return; } //move weapon to torso mount so that right hand is free if(this.MyReference.CurrentWeapon != null && MyAnimator.GetInteger("WeaponType") == (int)WeaponAnimType.Longgun) { this.MyReference.CurrentWeapon.transform.parent = this.MyReference.TorsoWeaponMount.transform; } MyAnimator.SetTrigger("TakeObject"); } if(command == CharacterCommands.Loot) { if(ActionState != HumanActionStates.None) { return; } GameObject useTarget = MyAI.BlackBoard.UseTarget; Character target = MyAI.BlackBoard.InteractTarget; if(target != null && target.MyStatus.Health <= 0) { if(this.MyAI.ControlType == AIControlType.Player) { UIEventHandler.Instance.TriggerLootBody(); } } else if(useTarget != null) { //open chest Chest chest = useTarget.GetComponent<Chest>(); if(chest != null) { //open UI UIEventHandler.Instance.TriggerLootChest(); } } } if(command == CharacterCommands.Talk) { if(ActionState != HumanActionStates.None) { return; } Debug.Log("opening dialog"); Character target = MyAI.BlackBoard.InteractTarget; if(target != null && target.MyStatus.Health > 0) { if(this.MyAI.ControlType == AIControlType.Player) { UIEventHandler.Instance.TriggerDialogue(); } } } if(command == CharacterCommands.SetAlert) { float ambient = RenderSettings.ambientIntensity; if(MyAI.BlackBoard.GuardLevel == 1) { //weapon holstered; only turn on flash light (if has one) when completely dark if(MyReference.CurrentWeapon != null) { SendCommand(CharacterCommands.Unarm); } if(MyReference.Flashlight != null) { if(ambient <= 0.3f) { MyReference.Flashlight.Toggle(true); } else { MyReference.Flashlight.Toggle(false); } } } else if(MyAI.BlackBoard.GuardLevel >= 2) { if(MyReference.CurrentWeapon == null) { SendCommand(MyAI.WeaponSystem.GetBestWeaponChoice()); } if(MyReference.Flashlight != null) { if(ambient <= 0.5f) { MyReference.Flashlight.Toggle(true); } else { MyReference.Flashlight.Toggle(false); } } } } }