예제 #1
0
        public override void OnChatButtonClicked(bool firstButton, ref bool shop)
        {
            if (firstButton)
            {
                Main.NewText("OK, I'll take your Pokémon for a few seconds.");
                Main.NewText("...");
                Main.NewText("Thank you for waiting.");
                Main.NewText("We've restored your Pokémon to full health.");
                Main.NewText("We hope to see you again!");

                for (int i = 0; i < Main.player[Main.myPlayer].inventory.Length; i++)
                {
                    PokemonWeapon pokemonWeapon = Main.player[Main.myPlayer].inventory[i].modItem as PokemonWeapon;
                    if (pokemonWeapon != null)
                    {
                        pokemonWeapon.currentHP = pokemonWeapon.maxHP;
                        pokemonWeapon.SetToolTip();
                        if (pokemonWeapon.npc != null)
                        {
                            pokemonWeapon.npc.life = pokemonWeapon.maxHP;
                            pokemonWeapon.npc.HealEffect(pokemonWeapon.maxHP);
                        }
                    }
                }
            }
        }
예제 #2
0
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            PokeModMessageType msgType = (PokeModMessageType)reader.ReadByte();

            switch (msgType)
            {
            // This message sent by the player when they load to initialize the custom Pokemon Weapon Data for all players
            case PokeModMessageType.SetPokemonWeaponData:

                break;

            case PokeModMessageType.SummonPokemon:
                int npc = NPC.NewNPC(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32());
                Main.npc[npc].releaseOwner = reader.ReadByte();
                Main.npc[npc].life         = reader.ReadInt32();

                PokemonNPC pokemon = Main.npc[npc].modNPC as PokemonNPC;
                if (pokemon != null)
                {
                    PokemonWeapon pokemonWeapon = Main.player[Main.npc[npc].releaseOwner].inventory[Main.player[Main.npc[npc].releaseOwner].selectedItem].modItem as PokemonWeapon;
                    if (pokemonWeapon != null)
                    {
                        pokemon.pokemon = pokemonWeapon;
                    }
                }
                break;

            default:
                ErrorLogger.Log("PokeMod: Unknown Message type: " + msgType);
                break;
            }
        }
예제 #3
0
 public override void OnHitByProjectile(NPC npc, Projectile projectile, int damage, float knockback, bool crit)
 {
     //check if hit by a pokemon projectile and save it
     if (projectile.modProjectile != null)
     {
         PokemonProjectile pokemonProjectile;
         pokemonProjectile = projectile.modProjectile as PokemonProjectile;
         if (pokemonProjectile != null)
         {
             lastHit = pokemonProjectile.pokemon;
         }
     }
 }
예제 #4
0
 // used to debug what information the server knows, essentially nothing, only the item owner actually saves and loads the stats of the item
 // so there is no central authoritative server for item information, so I cannot ask the server to tell everyone the stats of the pokemon, and only the server is allowed to send info
 public override void PostUpdate()
 {
     if (Main.netMode == 2)
     {
         for (int i = 0; i < Main.player.Length - 1; i++)
         {
             if (Main.player[i] != null)
             {
                 pokemon = Main.player[i].inventory[Main.player[i].selectedItem].modItem as PokemonWeapon;
                 ErrorLogger.Log(Main.player[i].name + " " + pokemon.ToString() + " " + pokemon.item.toolTip);
             }
         }
     }
 }
예제 #5
0
 public override void OnHitNPC(NPC npc, NPC target, int damage, float knockback, bool crit)
 {
     //check if hit a pokemon and save it
     if (target.modNPC != null)
     {
         PokemonNPC pokemonNPC;
         pokemonNPC = target.modNPC as PokemonNPC;
         if (pokemonNPC != null)
         {
             if (npc.releaseOwner == 255)
             {
                 lastHit = pokemonNPC.pokemon;
             }
         }
     }
 }
예제 #6
0
 public override void Kill(double damage, int hitDirection, bool pvp, string deathText)
 {
     for (int i = 0; i < player.inventory.Length; i++)
     {
         PokemonWeapon pokemonWeapon = player.inventory[i].modItem as PokemonWeapon;
         if (pokemonWeapon != null)
         {
             pokemonWeapon.currentHP = pokemonWeapon.maxHP;
             pokemonWeapon.SetToolTip();
             if (pokemonWeapon.npc != null)
             {
                 pokemonWeapon.npc.life = pokemonWeapon.maxHP;
                 pokemonWeapon.npc.HealEffect(pokemonWeapon.maxHP);
             }
         }
     }
 }
예제 #7
0
 public override bool UseItem(Player player)
 {
     for (int i = 0; i < Main.player[player.whoAmI].inventory.Length; i++)
     {
         PokemonWeapon pokemonWeapon = Main.player[player.whoAmI].inventory[i].modItem as PokemonWeapon;
         if (pokemonWeapon != null)
         {
             if (pokemonWeapon.npc != null)
             {
                 pokemonWeapon.npc.HealEffect(pokemonWeapon.maxHP - pokemonWeapon.npc.life);
                 pokemonWeapon.npc.life  = pokemonWeapon.maxHP;
                 pokemonWeapon.currentHP = pokemonWeapon.npc.life;
                 pokemonWeapon.SetToolTip();
                 return(true);
             }
         }
     }
     return(false);
 }
예제 #8
0
        public override void AI()
        {
            if (!set && npc.releaseOwner != 255)
            {
                if (Main.myPlayer == npc.releaseOwner)
                {
                    Main.NewText("Go " + npc.name + "!");
                }
                pokemon     = Main.player[npc.releaseOwner].inventory[Main.player[npc.releaseOwner].selectedItem].modItem as PokemonWeapon;
                level       = pokemon.level;
                nature      = pokemon.nature;
                HPIV        = pokemon.HPIV;
                AtkIV       = pokemon.AtkIV;
                DefIV       = pokemon.DefIV;
                SpAIV       = pokemon.SpAIV;
                SpDIV       = pokemon.SpDIV;
                SpeIV       = pokemon.SpeIV;
                HPEV        = pokemon.HPEV;
                AtkEV       = pokemon.AtkEV;
                DefEV       = pokemon.DefEV;
                SpAEV       = pokemon.SpAEV;
                SpDEV       = pokemon.SpDEV;
                SpeEV       = pokemon.SpeEV;
                npc.damage  = Atk;
                npc.defense = Def;
                npc.lifeMax = maxHP;
                npc.life    = maxHP;
                Main.player[npc.releaseOwner].AddBuff(mod.BuffType(Name + "Buff"), 3600);
                set = true;
            }
            if (!set && npc.releaseOwner == 255)
            {
                npc.friendly = false;
                set          = true;
            }

            if (npc.wet)
            {
                if (aiMode == swimming)
                {
                    movSpeed = speed * 2;
                }
                movSpeed = speed / 4;
            }
            else
            {
                if (aiMode == swimming)
                {
                    movSpeed = speed / 4;
                }
                movSpeed = speed;
            }

            int     pDirection;
            Vector2 pCenter;

            // look at each other active npc and if it is owned by this player then maintain a bit of spacing instead of all clumping up
            if (npc.releaseOwner != 255)
            {
                pCenter = Main.player[npc.releaseOwner].Center;
                if (aiMode == flying)
                {
                    pCenter.Y = pCenter.Y - 60f;
                }
                pDirection   = Main.player[npc.releaseOwner].direction;
                npc.friendly = true;
            }
            else
            {
                pCenter      = new Vector2(0, 0);
                pDirection   = 1;
                npc.friendly = false;
            }
            Vector2 targetPos  = npc.position;
            float   targetDist = viewDist;
            bool    target     = false;

            npc.noTileCollide = false;
            float spacing = (float)npc.width * spacingMult;

            if (npc.friendly)
            {
                for (int k = 0; k < 200; k++)
                {
                    NPC otherNPC = Main.npc[k];
                    if (k != npc.whoAmI && otherNPC.active && otherNPC.releaseOwner == npc.releaseOwner && System.Math.Abs(npc.position.X - otherNPC.position.X) + System.Math.Abs(npc.position.Y - otherNPC.position.Y) < spacing)
                    {
                        if (npc.position.X < otherNPC.position.X)
                        {
                            npc.velocity.X -= idleAccel;
                        }
                        else
                        {
                            npc.velocity.X += idleAccel;
                        }
                        if (npc.position.Y < otherNPC.position.Y)
                        {
                            if (aiMode == flying)
                            {
                                npc.velocity.Y -= idleAccel;
                            }
                        }
                        else
                        {
                            npc.velocity.Y += idleAccel;
                        }
                    }
                    if (otherNPC.CanBeChasedBy(this, false))
                    {
                        float distance = Vector2.Distance(otherNPC.Center, npc.Center);
                        if ((distance < targetDist || !target) && Collision.CanHitLine(npc.position, npc.width, npc.height, otherNPC.position, otherNPC.width, otherNPC.height))
                        {
                            targetDist = distance;
                            targetPos  = otherNPC.Center;
                            target     = true;
                        }
                    }
                }
            }
            else
            {
                // enemy npc ai for targeting

                // don't have a target? then get one
                if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active)
                {
                    npc.TargetClosest(true);
                }
                // now check again, if you have one set the location etc.
                if (!(npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active))
                {
                    targetPos   = Main.player[npc.target].position;
                    targetPos.Y = targetPos.Y + (Main.player[npc.target].height / 2);
                    target      = true;
                    pCenter     = Main.player[npc.target].Center;
                    pDirection  = Main.player[npc.target].direction;
                }
            }

            Vector2 myDirection;
            float   distanceTo;

            //if you have a target and you are at ai[0] state 0f, aka ready and not currently fleeing back to npc.releaseOwner
            if (target && npc.ai[0] == 0f)
            {
                // get the distance between this and it's target
                myDirection = targetPos - npc.Center;
                // if the distance is greater than 'chaseDist', the distance this engages enemies from
                if (myDirection.Length() > chaseDist)
                {
                    // then move toward the target
                    myDirection.Normalize();
                    npc.velocity = (npc.velocity * inertia + myDirection * chaseAccel) / (inertia + 1);
                }
                else
                {
                    //otherwise slowly come to a halt
                    npc.velocity *= (float)Math.Pow(0.97, 40.0 / inertia);
                }
            }
            else
            {
                if (npc.friendly)
                {
                    int num = 1;
                    myDirection = pCenter - npc.Center;
                    distanceTo  = myDirection.Length();
                    // if the distance is too great, just instant teleport to the player
                    if (distanceTo > 1000f)
                    {
                        npc.Center = pCenter;
                    }
                    npc.ai[1]     = 3600f;
                    npc.netUpdate = true;
                    if (distanceTo > 48f)
                    {
                        myDirection.Normalize();
                        myDirection *= movSpeed;
                        float temp = inertia / 2f;
                        npc.velocity = (npc.velocity * temp + myDirection) / (temp + 1);
                    }
                    else
                    {
                        npc.direction = pDirection;
                        npc.velocity *= (float)Math.Pow(0.9, 40.0 / inertia);
                        if (aiMode == flying) //************************* FLYING *************************
                        {
                            if (npc.velocity.X == 0f && npc.velocity.Y == 0f)
                            {
                                npc.velocity.X = -0.15f;
                                npc.velocity.Y = -0.05f;
                            }
                            npc.velocity *= 1.01f;
                        }
                    }
                }
            }


            npc.rotation = npc.velocity.X * 0.05f;
            if (npc.velocity.X > 0f)
            {
                npc.spriteDirection = (npc.direction = 1);
            }
            else if (npc.velocity.X < 0f)
            {
                npc.spriteDirection = (npc.direction = -1);
            }
            if (npc.ai[1] > 0f)
            {
                npc.ai[1] += 1f;
                if (Main.rand.Next(3) == 0)
                {
                    npc.ai[1] += 1f;
                }
            }
            if (npc.ai[1] > shootCool)
            {
                npc.ai[1]     = 0f;
                npc.netUpdate = true;
            }
            if (npc.ai[0] == 0f)
            {
                if (target)
                {
                    if ((targetPos - npc.Center).X > 0f)
                    {
                        npc.spriteDirection = (npc.direction = 1);
                    }
                    else if ((targetPos - npc.Center).X < 0f)
                    {
                        npc.spriteDirection = (npc.direction = -1);
                    }
                    if (npc.ai[1] == 0f)
                    {
                        npc.ai[1] = 1f;
                        if (Main.netMode != 1)
                        {
                            // shoot code
                            if (shoot != -1)
                            {
                                Vector2 shootVel = targetPos - npc.Center;
                                if (shootVel == Vector2.Zero)
                                {
                                    shootVel = new Vector2(0f, 1f);
                                }
                                shootVel.Normalize();
                                shootVel *= shootSpeed;
                                int owner;
                                if (npc.friendly)
                                {
                                    owner = Main.player[npc.releaseOwner].whoAmI;
                                }
                                else
                                {
                                    owner = 255;
                                }
                                int proj = Projectile.NewProjectile(npc.Center.X, npc.position.Y, shootVel.X, shootVel.Y, shoot, GetRangedDamage(), GetKnockback(), owner, 0f, 0f);
                                PokemonProjectile pokemonProjectile;
                                pokemonProjectile               = Main.projectile[proj].modProjectile as PokemonProjectile;
                                pokemonProjectile.pokemon       = this.pokemon;
                                Main.projectile[proj].timeLeft  = 300;
                                Main.projectile[proj].netUpdate = true;
                                if (owner == 255)
                                {
                                    Main.projectile[proj].friendly = false;
                                    Main.projectile[proj].hostile  = true;
                                }
                                else
                                {
                                    Main.projectile[proj].friendly = true;
                                    Main.projectile[proj].hostile  = false;
                                }
                                npc.netUpdate = true;
                            }
                        }
                    }
                }
            }
            // JUMP GAPS
            if (aiMode == running)
            {
                int xPos = (int)((npc.position.X + (float)(npc.width / 2) + (float)((npc.width / 2 + 16) * npc.direction)) / 16f);
                int yPos = (int)((npc.position.Y + (float)npc.height - 15f) / 16f);
                if (Main.tile[xPos, yPos] == null)
                {
                    Main.tile[xPos, yPos] = new Tile();
                }
                if (Main.tile[xPos, yPos - 1] == null)
                {
                    Main.tile[xPos, yPos - 1] = new Tile();
                }
                if (Main.tile[xPos, yPos - 2] == null)
                {
                    Main.tile[xPos, yPos - 2] = new Tile();
                }
                if (Main.tile[xPos, yPos - 3] == null)
                {
                    Main.tile[xPos, yPos - 3] = new Tile();
                }
                if (Main.tile[xPos, yPos + 1] == null)
                {
                    Main.tile[xPos, yPos + 1] = new Tile();
                }
                if (Main.tile[xPos + npc.direction, yPos - 1] == null)
                {
                    Main.tile[xPos + npc.direction, yPos - 1] = new Tile();
                }
                if (Main.tile[xPos + npc.direction, yPos + 1] == null)
                {
                    Main.tile[xPos + npc.direction, yPos + 1] = new Tile();
                }
                if (Main.tile[xPos - npc.direction, yPos + 1] == null)
                {
                    Main.tile[xPos - npc.direction, yPos + 1] = new Tile();
                }
                if ((npc.velocity.X < 0f && npc.spriteDirection == -1) || (npc.velocity.X > 0f && npc.spriteDirection == 1))
                {
                    if (Main.tile[xPos, yPos - 2].nactive() && Main.tileSolid[(int)Main.tile[xPos, yPos - 2].type])
                    {
                        if (Main.tile[xPos, yPos - 3].nactive() && Main.tileSolid[(int)Main.tile[xPos, yPos - 3].type])
                        {
                            npc.velocity.Y = -8f;
                            npc.netUpdate  = true;
                        }
                        else
                        {
                            npc.velocity.Y = -7f;
                            npc.netUpdate  = true;
                        }
                    }

                    /*
                     * if (Main.tile[xPos, yPos - 2].nactive() && Main.tileSolid[(int)Main.tile[xPos, yPos - 2].type])
                     * {
                     *  if (Main.tile[xPos, yPos - 3].nactive() && Main.tileSolid[(int)Main.tile[xPos, yPos - 3].type])
                     *  {
                     *      npc.velocity.Y = -8f;
                     *      npc.netUpdate = true;
                     *  }
                     *  else
                     *  {
                     *      npc.velocity.Y = -7f;
                     *      npc.netUpdate = true;
                     *  }
                     * }
                     */
                    /*
                     * else if (Main.tile[xPos, yPos - 1].nactive() && Main.tileSolid[(int)Main.tile[xPos, yPos - 1].type])
                     * {
                     *  npc.velocity.Y = -6f;
                     *  npc.netUpdate = true;
                     * }
                     * else if (npc.position.Y + (float)npc.height - (float)(yPos * 16) > 20f && Main.tile[xPos, yPos].nactive() && !Main.tile[xPos, yPos].topSlope() && Main.tileSolid[(int)Main.tile[xPos, yPos].type])
                     * {
                     *  npc.velocity.Y = -5f;
                     *  npc.netUpdate = true;
                     * }
                     * else if (npc.directionY < 0 && npc.type != 67 && (!Main.tile[xPos, yPos + 1].nactive() || !Main.tileSolid[(int)Main.tile[xPos, yPos + 1].type]) && (!Main.tile[xPos + npc.direction, yPos + 1].nactive() || !Main.tileSolid[(int)Main.tile[xPos + npc.direction, yPos + 1].type]))
                     * {
                     *  npc.velocity.Y = -8f;
                     *  npc.velocity.X = npc.velocity.X * 1.5f;
                     *  npc.netUpdate = true;
                     * }
                     */
                }

                /*
                 * if (npc.velocity.Y == 0f && Math.Abs(npc.position.X + (float)(npc.width / 2) - (Main.player[npc.target].position.X + (float)(Main.player[npc.target].width / 2))) < 100f && Math.Abs(npc.position.Y + (float)(npc.height / 2) - (Main.player[npc.target].position.Y + (float)(Main.player[npc.target].height / 2))) < 50f && ((npc.direction > 0 && npc.velocity.X >= 1f) || (npc.direction < 0 && npc.velocity.X <= -1f)))
                 * {
                 *  npc.velocity.X = npc.velocity.X * 2f;
                 *  if (npc.velocity.X > 3f)
                 *  {
                 *      npc.velocity.X = 3f;
                 *  }
                 *  if (npc.velocity.X < -3f)
                 *  {
                 *      npc.velocity.X = -3f;
                 *  }
                 *  npc.velocity.Y = -4f;
                 *  npc.netUpdate = true;
                 * }
                 */
            }
            if (capture > 0)
            {
                Capture();
            }
            CreateDust();
        }