public Client(Server server, Socket socket, byte playerId) { Socket = socket; Server = server; PlayerId = playerId; Leprechaun = new Leprechaun(this); }
// Update is called once per frame public virtual void Update() { if (health <= 0) { isDead = true; } healthHud.SetHealth(health); //if (GamePad.GetButtonDown(GamePad.Button.Back, gamePadIndex)) //{ // Camera.main.GetComponent<AdvancedCamera>().Zoom(new Vector2(gameObject.transform.position.x, gameObject.transform.position.y)); //} if (gameObject.transform.parent.gameObject.GetComponent <Player>().kills >= 5) { Global.WorldObject.GameWon(controllerNumber, chosenCharacter); //Global.WorldObject.winnerIndex = chosenPlayerIndex; } if (!IsDead && !isDrinking && !advancedCamera.asleep) { #region ATTACKING CODE if ((GamePad.GetButtonDown(GamePad.Button.X, gamePadIndex) || (useMpu && mpuController.GetDigitalPressed(9))) && onGround && !isDrinking) { if (playerScript.usePunchbag) { playerScript.punchBag.GetComponent <Punchbag>().Hit(gameObject.transform.position); if (punchCheck.collider2D.bounds.Intersects(playerScript.punchBag.collider2D.bounds)) { playerScript.punchBag.GetComponent <Punchbag>().Hit(gameObject.transform.position); print("check"); } } foreach (GameObject d in Global.drinks.ToArray()) { Drink drinkScript = d.GetComponent <Drink>(); if (bodyCheck.collider2D.bounds.Intersects(drinkScript.drinkCollision.collider2D.bounds)) { sortOfDrink = drinkScript.drinkType; GetDrunk(sortOfDrink); drinkScript.Remove(); isDrinking = true; playerObject.rigidbody2D.velocity = Vector2.zero; SetAnimation("isDrinking_1", true); SetAnimation("isDrinking_2", true); SetAnimation("typeOfDrink", drinkScript.drinkNumber); //Invoke("NotDrinking", .4f); } } } if ((GamePad.GetButtonDown(GamePad.Button.X, gamePadIndex) || (useMpu && mpuController.GetDigitalPressed(9))) && onGround && attackOnce == -1 && !isDrinking && attackCooldown == 0) { //playerState = PlayerStates.ATTACKING; isAttacking = true; SetAnimation("isAttacking", true); attackOnce = 1; attackCooldown = attackCooldownMax; bool didHit = false; foreach (GameObject lep in Global.leprechauns.ToArray()) { Player p = lep.gameObject.transform.parent.GetComponent <Player>(); if (punchCheck.collider2D.bounds.Intersects(p.GetCollisionObject("bodyCheck", lep).collider2D.bounds) && lep != gameObject) { if (p.GetLeprechaunScriptType().GetType() == typeof(Leprechaun)) { Leprechaun lepScript = (Leprechaun)p.leprechaunScript; lepScript.GotHit(gameObject.transform.position, damageMultiplayer, gamePadIndex, punchShakeHardness); didHit = true; lepScript.isHit = true; lepScript.SetAnimation("isHit", true); lepScript.Invoke("NotHit", .2f); } else if (p.GetLeprechaunScriptType().GetType() == typeof(Leprechaun_USA)) { Leprechaun_USA lepScript = (Leprechaun_USA)p.leprechaunScript; lepScript.GotHit(gameObject.transform.position, damageMultiplayer, gamePadIndex, punchShakeHardness); didHit = true; lepScript.isHit = true; lepScript.SetAnimation("isHit", true); lepScript.Invoke("NotHit", .2f); } else if (p.GetLeprechaunScriptType().GetType() == typeof(Cluirichaun)) { Cluirichaun lepScript = (Cluirichaun)p.leprechaunScript; lepScript.GotHit(gameObject.transform.position, damageMultiplayer, gamePadIndex, punchShakeHardness); didHit = true; lepScript.isHit = true; lepScript.SetAnimation("isHit", true); lepScript.Invoke("NotHit", .2f); } else if (p.GetLeprechaunScriptType().GetType() == typeof(FarDarrig)) { FarDarrig lepScript = (FarDarrig)p.leprechaunScript; lepScript.GotHit(gameObject.transform.position, damageMultiplayer, gamePadIndex, punchShakeHardness); didHit = true; lepScript.isHit = true; lepScript.SetAnimation("isHit", true); lepScript.Invoke("NotHit", .2f); } else if (p.GetLeprechaunScriptType().GetType() == typeof(Fairy)) { Fairy lepScript = (Fairy)p.leprechaunScript; lepScript.GotHit(gameObject.transform.position, damageMultiplayer, gamePadIndex, punchShakeHardness); didHit = true; lepScript.isHit = true; lepScript.SetAnimation("isHit", true); lepScript.Invoke("NotHit", .2f); } } } if (!didHit) { int i = UnityEngine.Random.Range(1, 6); gameObject.Stab(Resources.Load("Audio/SFX/Punch_Miss_" + i.ToString()) as AudioClip, 1f, 1f, 0f); } else { int i = UnityEngine.Random.Range(1, 6); gameObject.Stab(Resources.Load("Audio/SFX/Punch_Hit_" + i.ToString()) as AudioClip, 1f, 1f, 0f); } } if (attackOnce >= 1) { attackOnce -= 1; } else if (attackOnce == 0) { attackOnce = -1; attackDone = false; isAttacking = false; SetAnimation("isAttacking", false); } if (attackCooldown > 0) { attackCooldown--; } else if (attackCooldown < 0) { attackCooldown = 0; } #endregion #region BLOCKING CODE //if (GamePad.GetButtonDown(GamePad.Button.B, gamePadIndex) && !isDashing && !isAttacking && !isDrinking) //{ // isBlocking = true; // SetAnimation("isBlocking", true); //} //if (GamePad.GetButtonUp(GamePad.Button.B, gamePadIndex)) //{ // isBlocking = false; // SetAnimation("isBlocking", false); //} #endregion #region DASHING CODE //if ((GamePad.GetTrigger(GamePad.Trigger.LeftTrigger, gamePadIndex) > 0.1 || GamePad.GetTrigger(GamePad.Trigger.LeftTrigger, gamePadIndex) > 0.1) // && !isDashing && !isDashCooldown) //{ // isDashing = true; // dashTimer = 0; // //animation.GetAnimation.Start(); //} //if (isDashing) //{ // if (dashTimer > 10) // { // dashCooldown = 120; // isDashCooldown = true; // isDashing = false; // } // //playerState = PlayerStates.DASHING; // dashTimer++; // Dash(); //} //if (isDashCooldown) //{ // if (dashCooldown > 0) // dashCooldown--; // else // isDashCooldown = false; //} #endregion #region JUMPING CODE if (onGround && useMpu && !isAttacking && !isHit) { if (mpuController.GetSensor(MPUController.Axis.Y, MPUController.Side.NEGATIVE)) { SetAnimation("grounded", false); playerObject.rigidbody2D.AddForce(new Vector2(0, maxVelocity.y) / 5); } } else if (onGround && (GamePad.GetButtonDown(GamePad.Button.A, gamePadIndex) || GamePad.GetKeyboardKeyDown(KeyCode.Space)) && !isAttacking && !isHit) { SetAnimation("grounded", false); playerObject.rigidbody2D.AddForce(new Vector2(0, maxVelocity.y)); } if (!onGround && chosenCharacter == Player.Character.FAIRY && canDoubleJump && useMpu && !isAttacking && !isHit) { if (mpuController.GetSensor(MPUController.Axis.Y, MPUController.Side.NEGATIVE)) { Vector3 vel = playerObject.rigidbody2D.velocity; vel.y = 0; playerObject.rigidbody2D.velocity = vel; playerObject.rigidbody2D.AddForce(new Vector2(0, maxVelocity.y / 1.2f)); canDoubleJump = false; } } else if (!onGround && chosenCharacter == Player.Character.FAIRY && canDoubleJump && (GamePad.GetButtonDown(GamePad.Button.A, gamePadIndex) || GamePad.GetKeyboardKeyDown(KeyCode.Space)) && !isAttacking && !isHit) { Vector3 vel = playerObject.rigidbody2D.velocity; vel.y = 0; playerObject.rigidbody2D.velocity = vel; playerObject.rigidbody2D.AddForce(new Vector2(0, maxVelocity.y / 1.2f)); canDoubleJump = false; } #endregion } else if (isDrinking) { if (bottom_animator.GetCurrentAnimatorStateInfo(0).IsName("Drink") && bottom_animator.GetCurrentAnimatorStateInfo(0).normalizedTime > 1 && !bottom_animator.IsInTransition(0)) { NotDrinking(1, false); } if (bottom_animator.GetCurrentAnimatorStateInfo(0).IsName("Drink") && bottom_animator.GetCurrentAnimatorStateInfo(0).normalizedTime > 1 && !bottom_animator.IsInTransition(0)) { NotDrinking(2, true); } } //ManageDrunkness(); if (IsDead && deathCounter == 0) { SetAnimation("isDead", true); SetAnimation("grounded", true); SetAnimation("isHit", false); SetAnimation("isAttacking", false); SetAnimation("isBlocking", false); SetAnimation("isDrinking_1", false); SetAnimation("isDrinking_2", false); dustOnce = false; dustParticle.GetComponent <Animator>().SetBool("triggerOnce", false); gameObject.Stab(Resources.Load("Audio/SFX/Knockout") as AudioClip, 1f, 1f, 0f); healthHud.SetHealth(0); deathCounter++; } else if (IsDead && deathCounter == 1 && bottom_animator.GetCurrentAnimatorStateInfo(0).IsName("KnockOut")) { SetAnimation("deathCounter", deathCounter); SetAnimation("isDead", false); Global.leprechauns.Remove(gameObject); deathCounter++; } else if (IsDead && deathCounter == 2) { RespawnButton(); Camera.main.GetComponent <AdvancedCamera>().ZoomWithDelay(new Vector2(gameObject.transform.position.x, gameObject.transform.position.y), .1f); deathCounter++; } else if (IsDead && deathCounter == 3) { if (GamePad.GetButtonDown(GamePad.Button.X, gamePadIndex) || (useMpu && mpuController.GetDigitalPressed(9))) { respawnButton.GetComponent <RespawnButton>().RemoveRespawnButton(); playerScript.ResetPlayer(gameObject); } } }
public GameObject GetCollisionObject(string collisionName, GameObject leprechaun) { if (leprechaun.GetComponent <Leprechaun>() != null) { Leprechaun script = leprechaunScript.GetComponent <Leprechaun>(); if (collisionName == "groundCheck") { return(script.groundCheck); } else if (collisionName == "punchCheck") { return(script.punchCheck); } else if (collisionName == "bodyCheck") { return(script.bodyCheck); } else if (collisionName == "wallCheck") { return(script.wallCheck); } } else if (leprechaun.GetComponent <Leprechaun_USA>() != null) { Leprechaun_USA script = leprechaunScript.GetComponent <Leprechaun_USA>(); if (collisionName == "groundCheck") { return(script.groundCheck); } else if (collisionName == "punchCheck") { return(script.punchCheck); } else if (collisionName == "bodyCheck") { return(script.bodyCheck); } else if (collisionName == "wallCheck") { return(script.wallCheck); } } else if (leprechaun.GetComponent <Cluirichaun>() != null) { Cluirichaun script = leprechaunScript.GetComponent <Cluirichaun>(); if (collisionName == "groundCheck") { return(script.groundCheck); } else if (collisionName == "punchCheck") { return(script.punchCheck); } else if (collisionName == "bodyCheck") { return(script.bodyCheck); } else if (collisionName == "wallCheck") { return(script.wallCheck); } } else if (leprechaun.GetComponent <FarDarrig>() != null) { FarDarrig script = leprechaunScript.GetComponent <FarDarrig>(); if (collisionName == "groundCheck") { return(script.groundCheck); } else if (collisionName == "punchCheck") { return(script.punchCheck); } else if (collisionName == "bodyCheck") { return(script.bodyCheck); } else if (collisionName == "wallCheck") { return(script.wallCheck); } } else if (leprechaun.GetComponent <Fairy>() != null) { Fairy script = leprechaunScript.GetComponent <Fairy>(); if (collisionName == "groundCheck") { return(script.groundCheck); } else if (collisionName == "punchCheck") { return(script.punchCheck); } else if (collisionName == "bodyCheck") { return(script.bodyCheck); } else if (collisionName == "wallCheck") { return(script.wallCheck); } } return(gameObject); }
private void ProcessPacket(NetworkPacket packet) { switch (packet.Type) { case NetworkPacketTypes.Leprechaun: { Leprechaun.Set(new NetworkPacketDrawable(packet)); int index = NetworkPacketDrawable.GetOffset(); var flags = new BitArray(new[] { packet.Data[index++], packet.Data[index++], packet.Data[index++], packet.Data[index++] }); var beginFlags = new BitArray(new[] { packet.Data[index++], packet.Data[index++], packet.Data[index++], packet.Data[index++] }); Leprechaun.RainbowProgress = packet.Data[index]; Leprechaun.IsStunned = flags.Get((int)Flags.LeprechaunFlags.CaneHit); Leprechaun.IsFlying = flags.Get((int)Flags.LeprechaunFlags.Flying); Leprechaun.IsInvulnerable = flags.Get((int)Flags.LeprechaunFlags.Invulnerability); Leprechaun.IsStoneHit = flags.Get((int)Flags.LeprechaunFlags.StoneHit); Leprechaun.IsInvisible = flags.Get((int)Flags.LeprechaunFlags.Invisibility); Leprechaun.Hat.Enabled = flags.Get((int)Flags.LeprechaunFlags.Hat); Leprechaun.Cane.Enabled = flags.Get((int)Flags.LeprechaunFlags.Cane); if (Leprechaun.RainbowProgress >= 100) { if (Leprechaun.GetBoundingCylinder().Intersects(Rainbow)) { Vector3 direction = Vector3.Normalize(Config.GoldpotPosition - Rainbow.Point); Vector3 force = Vector3.Normalize(direction + Vector3.Up) * Config.RainbowKick; Send(new NetworkPacket(NetworkPacketTypes.Kick, force.ToByteArray())); } else if (Leprechaun.GetBoundingCylinder().Intersects(Goldpot)) { Server.OnGameOver(PlayerId); } } lock (Server.PigAI) { if ((Leprechaun.IsStunned || Leprechaun.IsFlying) && Server.PigAI.Pig.Captor == Leprechaun) { Server.PigAI.DropPig(); } if (beginFlags.Get((int)Flags.LeprechaunFlags.ThrowPig)) { Server.PigAI.ThrowPig(this); } if (beginFlags.Get((int)Flags.LeprechaunFlags.PigRobbery)) { if (Server.PigAI.Pig.Captor != null) { Server.PigAI.Pig.Captor.Client.Send(new NetworkPacket(NetworkPacketTypes.DropPig)); } Server.PigAI.CapturePig(this); } } Server.ItemsManager.CheckItemCollected(this); if (beginFlags.Get((int)Flags.LeprechaunFlags.ExplosionTrap)) { Trap newTrap = Server.TrapManager.AddTrap(PlayerId); newTrap.Position = Leprechaun.Position; newTrap.Scale = new Vector3(Config.TrapScale); newTrap.Rotation = Quaternion.Identity; newTrap.Velocity = Vector3.Zero; Server.Send(new NetworkPacketAddTrap(newTrap), this); } Trap trap = Server.TrapManager.IntersectsEnemyTrap(Leprechaun, PlayerId); if (trap != null) { lock (Server.TrapManager) { foreach (Client client in Server.GetClientList()) { float squaredDistance = (trap.Position - client.Leprechaun.Position).LengthSquared(); if (client.PlayerId != trap.PlayerId && !client.Leprechaun.IsInvulnerable && squaredDistance <= Config.TrapSquaredImpactRadius) { client.Send(new NetworkPacket(NetworkPacketTypes.Kick, ((-client.Leprechaun.GetDirection(trap) + Vector3.Up) * (Config.TrapExplosionPower - squaredDistance)).ToByteArray())); } } Server.Send(new NetworkPacketRemoveTrap(trap.PlayerId, trap.TrapId)); Server.TrapManager.RemoveTrap(trap); } } if (beginFlags.Get((int)Flags.LeprechaunFlags.Kick)) { foreach (Client client in Server.GetClientList(this).Where(c => !c.Leprechaun.IsInvulnerable && c.Leprechaun.IsKicked(Leprechaun))) { Vector3 force = Vector3.Normalize(Leprechaun.GetForward() + Vector3.Up) * Config.KickPower; if (flags.Get((int)Flags.LeprechaunFlags.AttackDouble)) { force *= Config.LeprechaunAttackDoubleFactor; } client.Send(new NetworkPacket(NetworkPacketTypes.Kick, force.ToByteArray())); } } } break; case NetworkPacketTypes.Hat: { Leprechaun.Hat.Set(new NetworkPacketDrawable(packet)); if (Leprechaun.Hat.Scale.Y <= Leprechaun.Scale.Y) { break; } foreach (Client client in Server.GetClientList(this).Where(c => !c.Leprechaun.IsInvulnerable && Leprechaun.Hat.Intersects(c.Leprechaun))) { client.Send(new NetworkPacket(NetworkPacketTypes.Kick, ((-client.Leprechaun.GetDirection(Leprechaun.Hat) + Vector3.Up * Config.HatUpPower) * Config.HatPower).ToByteArray())); } } break; case NetworkPacketTypes.Cane: { Leprechaun.Cane.Set(new NetworkPacketDrawable(packet)); foreach (Client client in Server.GetClientList(this).Where(c => !c.Leprechaun.IsInvulnerable && Leprechaun.Cane.Intersects(c.Leprechaun))) { client.Send(new NetworkPacket(NetworkPacketTypes.CaneHit, BitConverter.GetBytes(Config.CaneStunTime))); } } break; } }