/// <summary> /// Damage zombie /// </summary> /// <param name="damage">damage</param> /// <param name="indexPlayer">player index</param> public void ZombieDamage(int damage, int indexPlayer) { //Take damage Data_PlayerFile_Sr zm = RoomsManager.GetPlayerData(index); zm.Damage(damage); //If zombie not have target follow the attacking if (target == null) { Player_MovePlayer player = RoomsManager.GetPlayerController(indexPlayer); if (player) { target = player; player.AddFollowZombie(index); } } //If zombie death if (zm.HP <= 0) { Death(); string zmName = RoomsManager.GetPlayerData(index).nick; if (!string.IsNullOrEmpty(zmName)) { SQL_SavePlayerData.Kill(indexPlayer, zmName); } } }
//Check whether it is a character of the player and turn the player on its index, and gave him the coordinates of movement static public void OnPlMove(NetworkMessage netms) { Message_Sr.PlayerGoTo_Sr Go = netms.ReadMessage <Message_Sr.PlayerGoTo_Sr>(); if (Networking_OnConnect.AccountVerefication(Go.index, Go.login, Go.password)) { try { if (Go.keySend) { Player_MovePlayer move = GetPlayerController(Go.index); if (move) { move.Newposit(Go.key, Go.down); } } else { Player_MovePlayer move = GetPlayerController(Go.index); if (move) { move.axisY = Go.axisY; } } } catch (UnityException ex) { Debug.Log(ex.Message); Debug.Log("Networking_OnPlayerMove: ERROR"); } } }
public bool DisconnectPlayer(int index) { bool yes = false; if (index >= 0 && playersData.Count > index) { AccountData acc = Networking_OnConnect.GetAccountData(playersData[index].sessionID); if (acc != null) { yes = true; //Remove rooms data at account data acc.indexInRoom = -1; acc.roomID = -1; Message_Sr.DisconnectPlayer disc = new Message_Sr.DisconnectPlayer(); disc.ID = playersData[index].sessionID; RoomsManager.SendReliableToRoom(Networking_msgType_Sr.DisconnectPlayer, disc, roomID); //Remove player weapon Player_MovePlayer controll = playersData[index].playerMoveScript; if (controll.weaponOnMe) { RoomsManager.SendIntToAllRoom(Networking_msgType_Sr.RemoveItemOnScene, controll.weaponOnMe.index, roomID); RemoveItem(controll.weaponOnMe.index); } //Remove player data Destroy(playersData[index].playerObj); playersData[index] = null; playerListNULLVALLUE.Add(index); playerNumber--; } } return(yes); }
//If player standing close on zombie void OnTriggerStay(Collider col) { if (!death) { if (target == null) { //Check if this player if (col.CompareTag("Player")) { Player_MovePlayer pl = col.gameObject.GetComponent <Player_MovePlayer>(); if (!pl.death) { Vect = col.transform.position - transform.position; float angle = Vector3.Angle(transform.forward, Vect); //Check zombie see player? if (angle <= 90f) { target = pl; pl.AddFollowZombie(index); } else { //If zombie don't see player but player wery close to zombie if (4f > Vect.magnitude) { target = pl; pl.AddFollowZombie(index); } } } } } } }
//If target death //if zombie respawn automaticly //If player block move and fire, wait click respawn void Death() { death = true; NetworkWriter wr = new NetworkWriter(); wr.StartMessage(Networking_msgType_Sr.Death); wr.Write(index); wr.FinishMessage(); RoomsManager.SendReliableAtRoom(wr, index); if (zombie) { coll.enabled = false; CancelInvoke(); Invoke("Respawn", 20f); target.ZombieStopFollow(index); target = null; nav.destination = transform.position; CalculateDropChance(); } else { w = false; s = false; a = false; d = false; move = Vector3.zero; while (ZombieFollowMe.Count != 0) { RoomsManager.GetPlayerController(ZombieFollowMe[0]).FollowTargetDead(); ZombieFollowMe.RemoveAt(0); } } }
//If follow target death public void FollowTargetDead() { target = null; attack = false; nav.destination = transform.position; CancelInvoke(); }
static void PickUpWeapon(Player_Item_Sr item, Player_MovePlayer controll) { Player_Weapon_Sr weap = null; weap = item.gameObject.GetComponent <Player_Weapon_Sr>(); if (weap) { weap.TakeWeapon(controll.weapon, controll.index); } }
public static void HandleReload(NetworkMessage netMsg) { Message_Sr.PlayerAction action = netMsg.ReadMessage <Message_Sr.PlayerAction>(); if (Networking_OnConnect.AccountVerefication(action.index, action.log, action.pass)) { Player_MovePlayer pl = GetPlayerController(action.index); if (pl != null) { pl.StartReload(); } } }
public static void HandleRespawn(NetworkMessage netmsg) { Message_Sr.Respawn_Sr rs = netmsg.ReadMessage <Message_Sr.Respawn_Sr>(); if (Networking_OnConnect.AccountVerefication(rs.index, rs.log, rs.pass)) { Player_MovePlayer pl = GetPlayerController(rs.index); if (pl != null) { pl.Respawn(); } } }
public static void HandleDropWeapon(NetworkMessage netMsg) { Message_Sr.DropWeapon_Sr drop = netMsg.ReadMessage <Message_Sr.DropWeapon_Sr>(); if (Networking_OnConnect.AccountVerefication(drop.index, drop.log, drop.pass)) { Player_MovePlayer controll = GetPlayerController(drop.index); if (controll) { controll.DropWeapon(); } } }
public Player_MovePlayer GetPlayerControll(int index) { Player_MovePlayer d = null; if (index >= 0 && playersData.Count > index) { if (playersData[index] != null) { d = playersData[index].playerMoveScript; } } return(d); }
public static void HandlePickUpItem(NetworkMessage netMsg) { Message_Sr.PickUpWeapon_Sr pick = netMsg.ReadMessage <Message_Sr.PickUpWeapon_Sr>(); if (Networking_OnConnect.AccountVerefication(pick.index, pick.log, pick.pass)) { Player_MovePlayer controll = GetPlayerController(pick.index); if (controll) { controll.DropWeapon(); PickUpItem(pick.indexItem, controll); } } }
protected override void Shoot() { ammo--; for (int i = 0; i < shotVect.Length; i++) { shotVect[i].Set(transform.up.x + Random.Range(-tempF, tempF), transform.up.y, transform.up.z); } tempF += tempF; tempF = Mathf.Clamp(tempF, minBulletRage, maxBulletRage); //Send shoot all other player Message_Sr.Shot_Sr shot = new Message_Sr.Shot_Sr(); shot.index = shooterIndex; shot.type = type; shot.vect = new Vector3[shotVect.Length]; for (int i = 0; i < shotVect.Length; i++) { shot.vect[i] = shotVect[i]; } shot.thisPlayer = false; RoomsManager.SendToAllOtherPlayer(Networking_msgType_Sr.Fire, shot, shooterIndex); //Send shoot me shot.thisPlayer = true; shot.ammo = ammo; RoomsManager.SendToThisPlayer(Networking_msgType_Sr.Fire, shot, shooterIndex); foreach (Vector3 v in shotVect) { if (Physics.Raycast(transform.position, v.normalized, out hit, shotDistace, layerZombie, QueryTriggerInteraction.Ignore)) { Player_MovePlayer zombie = hit.transform.GetComponent <Player_MovePlayer>(); if (zombie != null) { zombie.ZombieDamage(damage, shooterIndex); } } } if (ammo > 0) { if (shotTime > 0) { Invoke("Shoot", shotTime); } } else { StartReload(); } }
/// <summary> /// Droped weapon /// </summary> /// <param name="force">Add force if true</param> public virtual void DropWeapon(bool force) { if (shooterIndex != -1) { Player_MovePlayer controll = RoomsManager.GetPlayerController(shooterIndex); controll.weaponOnMe = null; } shooterIndex = -1; updatePos = true; dropped = true; transform.SetParent(null); SetPhysics(true); if (force) { rig.AddForce(transform.up * 2, ForceMode.Force); } }
//Zombie attack done and can move void ZombieAttackDone() { if (target != null) { Player_MovePlayer targ = target.GetComponent <Player_MovePlayer>(); if (targ != null) { Data_PlayerFile_Sr data = RoomsManager.GetPlayerData(targ.index); data.Damage(RoomsManager.GetPlayerData(index).attackPower); if (data.HP <= 0) { targ.Death(); } } } attack = false; }
protected override void Shoot() { if (!delay) { delay = true; ammo--; temp.Set(transform.up.x + Random.Range(-tempF, tempF), transform.up.y, transform.up.z); tempF += tempF; tempF = Mathf.Clamp(tempF, minBulletRage, maxBulletRage); //Send shoot all other player Message_Sr.Shot_Sr shot = new Message_Sr.Shot_Sr(); shot.index = shooterIndex; shot.type = type; shot.vect = new Vector3[1]; shot.vect[0] = temp; shot.thisPlayer = false; RoomsManager.SendToAllOtherPlayer(Networking_msgType_Sr.Fire, shot, shooterIndex); //Send shoot me shot.thisPlayer = true; shot.ammo = ammo; RoomsManager.SendToThisPlayer(Networking_msgType_Sr.Fire, shot, shooterIndex); hits = Physics.RaycastAll(transform.position, temp.normalized, shotDistace, layerZombie, QueryTriggerInteraction.Ignore); if (hits.Length > 0) { foreach (RaycastHit hit in hits) { Player_MovePlayer zombie = hit.transform.GetComponent <Player_MovePlayer>(); if (zombie != null) { zombie.ZombieDamage(damage, shooterIndex); } } } if (ammo <= 0) { StartReload(); delay = false; } else { Invoke("Delay", shotTime); } } }
/// <summary> /// Disconnect and destroy all player, item and room /// </summary> public void DestroyRoom() { //Disconnect and destroy all player at room for (int index = 0; index < playersData.Count; index++) { int sessionID = playersData[index].sessionID; AccountData acc = Networking_OnConnect.GetAccountData(sessionID); if (acc != null) { //Remove rooms data at account data acc.indexInRoom = -1; acc.roomID = -1; Message_Sr.DisconnectPlayer disc = new Message_Sr.DisconnectPlayer(); disc.ID = sessionID; RoomsManager.SendToThisPlayer(Networking_msgType_Sr.DisconnectPlayer, disc, sessionID); //Remove player weapon Player_MovePlayer controll = playersData[index].playerMoveScript; if (controll.weaponOnMe) { RoomsManager.SendIntToAllRoom(Networking_msgType_Sr.RemoveItemOnScene, controll.weaponOnMe.index, roomID); RemoveItem(controll.weaponOnMe.index); } //Remove player data Destroy(playersData[index].playerObj); } } playersData.Clear(); playerListNULLVALLUE.Clear(); //Destroy all item in room for (int index = 0; index < ItemsList.Count; index++) { Player_Item_Sr item = ItemsList[index]; if (item) { Destroy(item.gameObject); } } ItemsList.Clear(); nullItem.Clear(); Destroy(gameObject); }
public static Player_MovePlayer GetPlayerController(int sessionID) { Player_MovePlayer data = null; AccountData acc = Networking_OnConnect.GetAccountData(sessionID); if (acc != null) { if (acc.roomID != -1 && acc.indexInRoom != -1) { Room room = GetRoom(acc.roomID); if (room) { data = room.GetPlayerControll(acc.indexInRoom); } } } return(data); }
static void PickUpItem(int itemIndex, Player_MovePlayer controll) { AccountData acc = Networking_OnConnect.GetAccountData(controll.index); Room room = GetRoom(acc.roomID); if (room) { Player_Item_Sr item = room.GetItem(itemIndex); if (item) { switch (item.ItemType) { case ItemType_Sr.weapon: PickUpWeapon(item, controll); break; } } } }
/// <summary> /// Player take this weapon /// </summary> /// <param name="obj">hand</param> /// <param name="sessionID">player index</param> public virtual void TakeWeapon(Transform obj, int sessionID) { updatePos = false; dropped = false; SetPhysics(false); transform.SetParent(obj, false); transform.localPosition = Vector3.zero; transform.localEulerAngles = euler; shooterIndex = sessionID; Player_MovePlayer controll = RoomsManager.GetPlayerController(sessionID); controll.weaponOnMe = this; //Send action to all player Message_Sr.PickUpWeapon_Sr up = new Message_Sr.PickUpWeapon_Sr(); up.index = controll.index; up.indexItem = index; up.thisPlayer = false; RoomsManager.SendToAllOtherPlayer(Networking_msgType_Sr.PickUp, up, controll.index); up.thisPlayer = true; up.ammo = ammo; up.ammoMax = maxAmmo; RoomsManager.SendToThisPlayer(Networking_msgType_Sr.PickUp, up, controll.index); }
//Add new player on map static void PlayerLoad(NetworkConnection con, Data_PlayerFile_Sr data, int roomID) { Room room = GetRoom(roomID); if (room) { GameObject go = (GameObject)Instantiate((GameObject)Resources.Load("Player"), room.spawnPosition, Quaternion.identity); go.name = data.nick; Player_MovePlayer move = go.GetComponent <Player_MovePlayer>(); move.playerCon = con; PlayerConnectToRoom(roomID, data, go); Message_Sr.NewPlayerOnScene_Sr newPL = new Message_Sr.NewPlayerOnScene_Sr(); newPL.player = GetPlayerData(data.sessionID); SendReliableToRoom(Networking_msgType_Sr.NewPlayerConnnectOnScene, newPL, roomID); Player_Weapon_Sr weap = InstantiateWeapon(weaponType_Sr.GaussGun, roomID); if (weap) { weap.TakeWeapon(move.weapon, data.sessionID); } } }