public void Rotate() { Player = FindObjectOfType <SurvivalPlayer>(); if (Character.Direction == true) { rotationOffset = 0.0f; } else { rotationOffset = -180f; } // Debug.Log(Character.gameObject.name); if (Character.tag == "Player") { difference = PlayerCamera.ScreenToWorldPoint(Input.mousePosition) - transform.position; difference.Normalize(); float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.Euler(0f, 0f, rotZ + rotationOffset); } else { difference = Player.EnemyAimLocation.position - transform.position; // difference.Normalize(); float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg; Quaternion rotation = Quaternion.AngleAxis(rotZ + 10, Vector3.forward); // transform.rotation = Quaternion.Slerp(transform.rotation, rotation, speed * Time.deltaTime + rotationOffset); transform.rotation = Quaternion.Euler(0f, 0f, rotZ + rotationOffset); } }
private void Start() { if (Player == null) { Player = FindObjectOfType <SurvivalPlayer>(); } }
private void Start() { if (player == null) { player = GameObject.FindGameObjectWithTag("Player").GetComponent <SurvivalPlayer>(); } DifficultyManager = FindObjectOfType <DifficultyManager>(); playerWeaponDamage = 10 * (6 - DifficultyManager.SurvivalDifficulty); }
private void SaveChest(Player p, Inventory inv) { SurvivalPlayer sP = _playersList.PlayerMap[p]; string folderPath = "./text/survivalPlugin/chests/" + p.level.name + "/"; string chestPath = folderPath + p.truename + "-" + sP.chestSelected.X + "," + sP.chestSelected.Y + "," + sP.chestSelected.Z; if (System.IO.File.Exists(chestPath)) { inv.Save(chestPath); } }
private Inventory GetChest(Player p) { SurvivalPlayer sP = _playersList.PlayerMap[p]; Inventory cInv = new Inventory(27); string folderPath = "./text/survivalPlugin/chests/" + p.level.name + "/"; string chestPath = folderPath + p.truename + "-" + sP.chestSelected.X + "," + sP.chestSelected.Y + "," + sP.chestSelected.Z; if (!cInv.Load(chestPath)) { p.Message("Chest not owned by you!"); return(null); } return(cInv); }
// Update is called once per frame void Update() { if (Player != null) { // Debug.Log("Enemy pos: " + gameObject.transform.position + " player pos: " + Player.transform.position + " dir: "+ Direction); gameObject.transform.position = Vector2.MoveTowards(gameObject.transform.position, Player.transform.position, MaxSpeed); } else { Player = FindObjectOfType <SurvivalPlayer>(); } if (!IsJumping) { JumpChance = Random.Range(0, 20); } else if (JumpChance == 0) { // Jump(); // Vector2 Test = new Vector2(Player.transform.position.x, Player.transform.position.y + JumpForce); // gameObject.transform.position = Vector2.MoveTowards(gameObject.transform.position, new Vector2(Player.transform.position.x, Player.transform.position.y + JumpForce), 0.2f); //gameObject.transform.position = new Vector2(gameObject.transform.position.x, Mathf.Lerp(gameObject.transform.position.y, JumpForce, Time.deltaTime)); } if (JumpChance == 0) { // IsJumping = true; // Jump(); } // If the input is moving the player right and the player is facing left... if (Player.transform.position.x > gameObject.transform.position.x && !Direction && Player != null) { // ... flip the player. Controller.Flip(); Direction = !Direction; } // Otherwise if the input is moving the player left and the player is facing right... else if (Player.transform.position.x < gameObject.transform.position.x && Direction && Player != null) { // ... flip the player. Controller.Flip(); Direction = !Direction; } //AIShoot(); StartCoroutine(FireGun()); }
private void Attack() { foreach (Player pl in _survivalPlayers.PlayerMap.Keys) { SurvivalPlayer sPl = _survivalPlayers.PlayerMap[pl]; int dist = Helpers.calculDistance(pl.Pos, _pos); if (dist > _width + _height) { continue; } if (HitTestPlayer(pl)) { sPl.SubHp(1); if (sPl.getHp() <= 0) { sPl.killPlayer("has been killed by a monster."); } } } }
// Use this for initialization void Start() { if (Player == null) { Player = FindObjectOfType <SurvivalPlayer>(); } Controller.m_Anim.SetFloat("Speed", 0.2f); if (Player.transform.position.x > gameObject.transform.position.x) { Direction = true; } else { Direction = false; Controller.Flip(); } EnemyStartHealth = 100; EnemyCurrentHealth = EnemyStartHealth; wasDamaged = false; // JumpForce = 35; IsJumping = false; DifficultyManager = FindObjectOfType <DifficultyManager>(); }
public void Execute(Player p, string[] args) { if (!_survivalMaps.Maps.Contains(p.Level.name)) { return; } SurvivalPlayer sP = _playersList.PlayerMap[p]; try { switch (args[0]) { case "see": if (sP.chestSelected.X == -1) { p.Message("First, select a chest. (Right click on it)"); break; } if (!checkChestDist(sP)) { p.Message("Too far from the selected chest."); break; } Inventory cInv = GetChest(p); if (cInv == null) { return; } p.Message(cInv.getString(p)); break; case "place": if (sP.chestSelected.X == -1) { p.Message("First, select a chest. (Right click on it)"); break; } if (!checkChestDist(sP)) { p.Message("Too far from the selected chest."); break; } ushort id = Block.Parse(p, args[1]); int quantity = int.Parse(args[2]); Inventory cInv2 = GetChest(p); if (cInv2 == null) { return; } if (quantity <= 0) { return; } if (sP.haveItem(id, quantity)) { int durability = sP.getDurability(id); if (!cInv2.AddItem(id, quantity, durability)) { p.Message("Chest Full."); break; } sP.Consume(id, quantity); SaveChest(p, cInv2); } break; case "take": if (sP.chestSelected.X == -1) { p.Message("First, select a chest. (Right click on it)"); break; } if (!checkChestDist(sP)) { p.Message("Too far from the selected chest."); break; } ushort id2 = Block.Parse(p, args[1]); int quantity2 = int.Parse(args[2]); Inventory cInv3 = GetChest(p); if (cInv3 == null) { return; } if (quantity2 <= 0) { return; } if (cInv3.contains(id2, quantity2)) { int durability = cInv3.getDurability(id2); if (!sP.Collect(id2, quantity2, durability)) { p.Message("Inventory Full."); break; } cInv3.RemoveItem(id2, quantity2); SaveChest(p, cInv3); } break; default: help(p); break; } } catch { help(p); } }
private bool checkChestDist(SurvivalPlayer sP) { int dist = Helpers.calculDistance(sP.chestSelected, new Position(sP.thisPlayer.Pos.BlockX, sP.thisPlayer.Pos.BlockY, sP.thisPlayer.Pos.BlockZ)); return(dist < 8); }
public static void KillPlayer(SurvivalPlayer player) { Destroy(player.gameObject); gm.StartCoroutine(gm.RespawnPlayer()); }
public static void Triggering(Player p, byte actionType, string args, ushort x, ushort y, ushort z, SurvivalPlayers survivalPlayers, ushort blockID) { try{ string[] argsA = args.Split(' '); int offsetX = 0; int offsetY = 0; int offsetZ = 0; switch (actionType) { case 0: p.SendMessage(args); break; case 1: if (argsA.Length > 1) { offsetX = int.Parse(argsA[1]); offsetY = int.Parse(argsA[2]); offsetZ = int.Parse(argsA[3]); if (argsA.Length > 4) { string[] BlocksConditions = argsA[4].Split(','); bool pass = false; for (int i = 0; i < BlocksConditions.Length; i++) { ushort b = Helpers.IDConvert(ushort.Parse(BlocksConditions[i])); if (b == p.level.GetBlock((ushort)(x + offsetX), (ushort)(y + offsetY), (ushort)(z + offsetZ))) { pass = true; } } if (!pass) { return; } } } if (argsA.Length > 5) { if (bool.Parse(argsA[5])) { offsetX = 0; offsetY = 0; offsetZ = 0; } } p.level.UpdateBlock(p, (ushort)(x + offsetX), (ushort)(y + offsetY), (ushort)(z + offsetZ), ushort.Parse(argsA[0])); break; case 2: offsetX = int.Parse(argsA[0]); offsetY = int.Parse(argsA[1]); offsetZ = int.Parse(argsA[2]); string[] BConditions = argsA[3].Split(','); bool Bpass = false; for (int i = 0; i < BConditions.Length; i++) { ushort b = Helpers.IDConvert(ushort.Parse(BConditions[i])); if (b == p.level.GetBlock((ushort)(x + offsetX), (ushort)(y + offsetY), (ushort)(z + offsetZ))) { Bpass = true; } } if (!Bpass) { return; } ushort BlockAt = p.level.GetBlock((ushort)(x + offsetX), (ushort)(y + offsetY), (ushort)(z + offsetZ)); if (ActionsBlocks.isActionBlockTrigger(BlockAt, 4)) { Timer t = new Timer(); t.Interval = 100; //In milliseconds here t.AutoReset = true; //Stops it from repeating t.Elapsed += (sender, e) => DoAction2(sender, e, p, BlockAt, (ushort)(x + offsetX), (ushort)(y + offsetY), (ushort)(z + offsetZ)); t.Start(); } break; case 3: //--------------------------- ushort[] blocks = { ushort.Parse(argsA[0]), ushort.Parse(argsA[1]), ushort.Parse(argsA[2]) }; int[] pos = { 0, 0, 0, 0 }; //N,W,S,E ushort uB = blocks[0]; for (int cx = -1; cx <= 1; cx++) { for (int cz = -1; cz <= 1; cz++) { if (cx == 0 && cz == 0) { continue; } if (cx + cz == 1 || cx + cz == -1) { for (int i = 0; i < blocks.Length; i++) { if (p.level.GetBlock((ushort)(x + cx), y, (ushort)(z + cz)) == blocks[i]) { if (cx == 1) { pos[1] = 1; } if (cx == -1) { pos[3] = 1; } if (cz == 1) { pos[0] = 1; } if (cz == -1) { pos[2] = 1; } } } } } } string sPos = pos[0] + " " + pos[1] + " " + pos[2] + " " + pos[3]; if (sPos == "1 0 0 0" || sPos == "1 0 1 0" || sPos == "0 0 1 0") { uB = blocks[1]; } else if (sPos == "0 1 0 0" || sPos == "0 1 0 1" || sPos == "0 0 0 1") { uB = blocks[2]; } p.level.UpdateBlock(p, x, y, z, uB); break; //------------------------------------------- case 4: ushort id = Helpers.IDConvert(ushort.Parse(argsA[0])); int hp = int.Parse(argsA[1]); SurvivalPlayer sp = survivalPlayers.PlayerMap[p]; if (sp.haveItem(id, 1)) { sp.Consume(id, 1); sp.AddHp(hp); } break; case 5: SurvivalPlayer sp2 = survivalPlayers.PlayerMap[p]; string folderPath = "./text/survivalPlugin/chests/" + p.level.name + "/"; string chestPath = folderPath + p.truename + "-" + x + "," + y + "," + z; if (!System.IO.File.Exists(chestPath)) { Inventory rawInv = new Inventory(27); rawInv.Save(chestPath); p.SendMessage("You are now owning this chest."); } sp2.SelectChest(x, y, z); break; case 6: SurvivalPlayer sp3 = survivalPlayers.PlayerMap[p]; string folderPath2 = "./text/survivalPlugin/chests/" + p.level.name + "/"; string chestPath2 = folderPath2 + p.truename + "-" + x + "," + y + "," + z; if (System.IO.File.Exists(chestPath2)) { System.IO.File.Delete(chestPath2); sp3.chestSelected = new Position(-1, -1, -1); } else { p.SendMessage("You are not owning this chest."); p.cancelBlock = true; p.RevertBlock(x, y, z); sp3.Consume(Helpers.getNorthBlock(blockID, p), 1); } break; default: p.SendMessage("Invalid Action."); break; } } catch { p.SendMessage("Invalid arguments."); } }