Пример #1
0
        /// <summary>Raised after the player loads a save slot.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void onSaveLoaded(object sender, SaveLoadedEventArgs e)
        {
            try
            {
                if (!Game1.IsMultiplayer || Game1.IsMasterGame)
                {
                    Log.info($"Loading save data (\"{MultiplayerSaveData.FilePath}\")...");
                    Data = File.Exists(MultiplayerSaveData.FilePath)
                        ? JsonConvert.DeserializeObject <MultiplayerSaveData>(File.ReadAllText(MultiplayerSaveData.FilePath))
                        : new MultiplayerSaveData();

                    foreach (var magic in Data.players)
                    {
                        if (magic.Value.spellBook.prepared[0].Length == 4)
                        {
                            var newSpells = new PreparedSpell[5];
                            for (int i = 0; i < 4; ++i)
                            {
                                newSpells[i] = magic.Value.spellBook.prepared[0][i];
                            }
                            magic.Value.spellBook.prepared[0] = newSpells;
                        }

                        if (magic.Value.spellBook.prepared[1].Length == 4)
                        {
                            var newSpells = new PreparedSpell[5];
                            for (int i = 0; i < 4; ++i)
                            {
                                newSpells[i] = magic.Value.spellBook.prepared[1][i];
                            }
                            magic.Value.spellBook.prepared[1] = newSpells;
                        }
                    }

                    if (!Data.players.ContainsKey(Game1.player.UniqueMultiplayerID))
                    {
                        Data.players[Game1.player.UniqueMultiplayerID] = new MultiplayerSaveData.PlayerData();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.warn($"Exception loading save data: {ex}");
            }
        }
Пример #2
0
        /// <summary>Raised after the player presses a button on the keyboard, controller, or mouse.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private static void onButtonPressed(object sender, ButtonPressedEventArgs e)
        {
            bool hasFifthSpellSlot = Game1.player.HasCustomProfession(Skill.ProfessionFifthSpellSlot);

            if (e.Button == Config.Key_Cast)
            {
                castPressed = true;
            }

            if (Data == null || Game1.activeClickableMenu != null)
            {
                return;
            }
            if (e.Button == Config.Key_SwapSpells)
            {
                Game1.player.getSpellBook().swapPreparedSet();
            }
            else if (castPressed &&
                     (e.Button == Config.Key_Spell1 || e.Button == Config.Key_Spell2 ||
                      e.Button == Config.Key_Spell3 || e.Button == Config.Key_Spell4 ||
                      (e.Button == Config.Key_Spell5 && hasFifthSpellSlot)))
            {
                int slot = 0;
                if (e.Button == Config.Key_Spell1)
                {
                    slot = 0;
                }
                else if (e.Button == Config.Key_Spell2)
                {
                    slot = 1;
                }
                else if (e.Button == Config.Key_Spell3)
                {
                    slot = 2;
                }
                else if (e.Button == Config.Key_Spell4)
                {
                    slot = 3;
                }
                else if (e.Button == Config.Key_Spell5)
                {
                    slot = 4;
                }

                Magic.inputHelper.Suppress(e.Button);

                SpellBook       book     = Game1.player.getSpellBook();
                PreparedSpell[] prepared = book.getPreparedSpells();
                if (prepared[slot] == null)
                {
                    return;
                }
                PreparedSpell prep = prepared[slot];

                Spell toCast = SpellBook.get(prep.SpellId);
                if (toCast == null)
                {
                    return;
                }

                //Log.trace("MEOW " + prep.SpellId + " " + prep.Level + " " + Game1.player.canCastSpell(toCast, prep.Level));
                if (Game1.player.canCastSpell(toCast, prep.Level))
                {
                    Log.trace("Casting " + prep.SpellId);

                    IActiveEffect effect = Game1.player.castSpell(toCast, prep.Level);
                    if (effect != null)
                    {
                        activeEffects.Add(effect);
                    }
                    Game1.player.addMana(-toCast.getManaCost(Game1.player, prep.Level));
                }
            }
        }
Пример #3
0
        /// <summary>Raised after drawing the HUD (item toolbar, clock, etc) to the sprite batch, but before it's rendered to the screen. The vanilla HUD may be hidden at this point (e.g. because a menu is open).</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        public static void onRenderedHud(object sender, RenderedHudEventArgs e)
        {
            if (Game1.activeClickableMenu != null || Game1.eventUp || Game1.player.getMaxMana() == 0)
            {
                return;
            }

            SpriteBatch b = e.SpriteBatch;

            Vector2 manaPos = new Vector2(20, Game1.viewport.Height - manaBg.Height * 4 - 20);

            b.Draw(manaBg, manaPos, new Rectangle(0, 0, manaBg.Width, manaBg.Height), Color.White, 0, new Vector2(), 4, SpriteEffects.None, 1);
            if (Game1.player.getCurrentMana() > 0)
            {
                Rectangle targetArea = new Rectangle(3, 13, 6, 41);
                float     perc       = Game1.player.getCurrentMana() / (float)Game1.player.getMaxMana();
                int       h          = (int)(targetArea.Height * perc);
                targetArea.Y     += targetArea.Height - h;
                targetArea.Height = h;

                targetArea.X      *= 4;
                targetArea.Y      *= 4;
                targetArea.Width  *= 4;
                targetArea.Height *= 4;
                targetArea.X      += (int)manaPos.X;
                targetArea.Y      += (int)manaPos.Y;
                b.Draw(manaFg, targetArea, new Rectangle(0, 0, 1, 1), Color.White);

                if ((double)Game1.getOldMouseX() >= (double)targetArea.X && (double)Game1.getOldMouseY() >= (double)targetArea.Y && (double)Game1.getOldMouseX() < (double)targetArea.X + targetArea.Width && Game1.getOldMouseY() < targetArea.Y + targetArea.Height)
                {
                    Game1.drawWithBorder(Math.Max(0, (int)Game1.player.getCurrentMana()).ToString() + "/" + Game1.player.getMaxMana(), Color.Black * 0.0f, Color.White, new Vector2(Game1.getOldMouseX(), Game1.getOldMouseY() - 32));
                }
            }

            bool hasFifthSpellSlot = Game1.player.HasCustomProfession(Skill.ProfessionFifthSpellSlot);

            int spotYAffector = -1;

            if (hasFifthSpellSlot)
            {
                spotYAffector = 0;
            }
            Point[] spots =
                new Point[5]/*
                             * {
                             * new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 40, Game1.viewport.Height - 20 - 50 - 30 - 50 - 25),
                             * new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 50 + 30, Game1.viewport.Height - 20 - 50 - 40 - 25),
                             * new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 40, Game1.viewport.Height - 20 - 50 - 25 ),
                             * new Point((int)manaPos.X + manaBg.Width * 4 + 20, Game1.viewport.Height - 20 - 50 - 40 - 25 ),
                             * };*/
            {
                new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 60 * 0, Game1.viewport.Height - 20 - 50 - 60 * (4 + spotYAffector)),
                new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 60 * 0, Game1.viewport.Height - 20 - 50 - 60 * (3 + spotYAffector)),
                new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 60 * 0, Game1.viewport.Height - 20 - 50 - 60 * (2 + spotYAffector)),
                new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 60 * 0, Game1.viewport.Height - 20 - 50 - 60 * (1 + spotYAffector)),
                new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 60 * 0, Game1.viewport.Height - 20 - 50 - 60 * (0 + spotYAffector)),
            };

            SpellBook book = Game1.player.getSpellBook();

            if (book == null || book.selectedPrepared >= book.prepared.Length)
            {
                return;
            }
            PreparedSpell[] prepared = book.getPreparedSpells();

            for (int i = 0; i < (hasFifthSpellSlot ? 5 : 4); ++i)
            {
                b.Draw(spellBg, new Rectangle(spots[i].X, spots[i].Y, 50, 50), Color.White);
            }

            string prepStr = (book.selectedPrepared + 1) + "/" + book.prepared.Length;

            b.DrawString(Game1.dialogueFont, prepStr, new Vector2(spots[Game1.down].X + 25 + 2, spots[Game1.up].Y - 35 + 0), Color.Black, 0, new Vector2(Game1.dialogueFont.MeasureString(prepStr).X / 2, 0), 0.6f, SpriteEffects.None, 0);
            b.DrawString(Game1.dialogueFont, prepStr, new Vector2(spots[Game1.down].X + 25 - 2, spots[Game1.up].Y - 35 + 0), Color.Black, 0, new Vector2(Game1.dialogueFont.MeasureString(prepStr).X / 2, 0), 0.6f, SpriteEffects.None, 0);
            b.DrawString(Game1.dialogueFont, prepStr, new Vector2(spots[Game1.down].X + 25 + 0, spots[Game1.up].Y - 35 + 2), Color.Black, 0, new Vector2(Game1.dialogueFont.MeasureString(prepStr).X / 2, 0), 0.6f, SpriteEffects.None, 0);
            b.DrawString(Game1.dialogueFont, prepStr, new Vector2(spots[Game1.down].X + 25 + 0, spots[Game1.up].Y - 35 - 2), Color.Black, 0, new Vector2(Game1.dialogueFont.MeasureString(prepStr).X / 2, 0), 0.6f, SpriteEffects.None, 0);
            b.DrawString(Game1.dialogueFont, prepStr, new Vector2(spots[Game1.down].X + 25, spots[Game1.up].Y - 35), Color.White, 0, new Vector2(Game1.dialogueFont.MeasureString(prepStr).X / 2, 0), 0.6f, SpriteEffects.None, 0);

            for (int i = 0; i < (hasFifthSpellSlot ? 5 : 4); ++i)
            {
                if (i >= prepared.Length)
                {
                    break;
                }

                PreparedSpell prep = prepared[i];
                if (prep == null)
                {
                    continue;
                }

                Spell spell = SpellBook.get(prep.SpellId);
                if (spell == null || spell.Icons.Length <= prep.Level || spell.Icons[prep.Level] == null)
                {
                    continue;
                }

                b.Draw(spell.Icons[prep.Level], new Rectangle(spots[i].X, spots[i].Y, 50, 50), Game1.player.canCastSpell(spell, prep.Level) ? Color.White : new Color(128, 128, 128));
            }
        }
Пример #4
0
        /// <summary>Raised after drawing the HUD (item toolbar, clock, etc) to the sprite batch, but before it's rendered to the screen. The vanilla HUD may be hidden at this point (e.g. because a menu is open).</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        public static void onRenderedHud(object sender, RenderedHudEventArgs e)
        {
            if (Game1.activeClickableMenu != null || Game1.eventUp || Game1.player.getMaxMana() == 0)
            {
                return;
            }

            SpriteBatch b = e.SpriteBatch;

            Vector2 manaPos = new Vector2(20, Game1.viewport.Height - manaBg.Height * 4 - 20);

            b.Draw(manaBg, manaPos, new Rectangle(0, 0, manaBg.Width, manaBg.Height), Color.White, 0, new Vector2(), 4, SpriteEffects.None, 1);
            if (Game1.player.getCurrentMana() > 0)
            {
                Rectangle targetArea = new Rectangle(3, 13, 6, 41);
                float     perc       = Game1.player.getCurrentMana() / (float)Game1.player.getMaxMana();
                int       h          = (int)(targetArea.Height * perc);
                targetArea.Y     += targetArea.Height - h;
                targetArea.Height = h;

                targetArea.X      *= 4;
                targetArea.Y      *= 4;
                targetArea.Width  *= 4;
                targetArea.Height *= 4;
                targetArea.X      += (int)manaPos.X;
                targetArea.Y      += (int)manaPos.Y;
                b.Draw(manaFg, targetArea, new Rectangle(0, 0, 1, 1), Color.White);
            }

            Point[] spots =
                new Point[4]/*
                             * {
                             * new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 40, Game1.viewport.Height - 20 - 50 - 30 - 50 - 25),
                             * new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 50 + 30, Game1.viewport.Height - 20 - 50 - 40 - 25),
                             * new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 40, Game1.viewport.Height - 20 - 50 - 25 ),
                             * new Point((int)manaPos.X + manaBg.Width * 4 + 20, Game1.viewport.Height - 20 - 50 - 40 - 25 ),
                             * };*/
            {
                new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 60 * 0, Game1.viewport.Height - 20 - 50 - 60 * 3),
                new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 60 * 0, Game1.viewport.Height - 20 - 50 - 60 * 2),
                new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 60 * 0, Game1.viewport.Height - 20 - 50 - 60 * 1),
                new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 60 * 0, Game1.viewport.Height - 20 - 50 - 60 * 0),
            };

            SpellBook book = Game1.player.getSpellBook();

            if (book == null || book.selectedPrepared >= book.prepared.Length)
            {
                return;
            }
            PreparedSpell[] prepared = book.getPreparedSpells();

            for (int i = 0; i < spots.Length; ++i)
            {
                b.Draw(spellBg, new Rectangle(spots[i].X, spots[i].Y, 50, 50), Color.White);
            }

            string prepStr = (book.selectedPrepared + 1) + "/" + book.prepared.Length;

            b.DrawString(Game1.dialogueFont, prepStr, new Vector2(spots[Game1.down].X + 25 + 2, spots[Game1.up].Y - 35 + 0), Color.Black, 0, new Vector2(Game1.dialogueFont.MeasureString(prepStr).X / 2, 0), 0.6f, SpriteEffects.None, 0);
            b.DrawString(Game1.dialogueFont, prepStr, new Vector2(spots[Game1.down].X + 25 - 2, spots[Game1.up].Y - 35 + 0), Color.Black, 0, new Vector2(Game1.dialogueFont.MeasureString(prepStr).X / 2, 0), 0.6f, SpriteEffects.None, 0);
            b.DrawString(Game1.dialogueFont, prepStr, new Vector2(spots[Game1.down].X + 25 + 0, spots[Game1.up].Y - 35 + 2), Color.Black, 0, new Vector2(Game1.dialogueFont.MeasureString(prepStr).X / 2, 0), 0.6f, SpriteEffects.None, 0);
            b.DrawString(Game1.dialogueFont, prepStr, new Vector2(spots[Game1.down].X + 25 + 0, spots[Game1.up].Y - 35 - 2), Color.Black, 0, new Vector2(Game1.dialogueFont.MeasureString(prepStr).X / 2, 0), 0.6f, SpriteEffects.None, 0);
            b.DrawString(Game1.dialogueFont, prepStr, new Vector2(spots[Game1.down].X + 25, spots[Game1.up].Y - 35), Color.White, 0, new Vector2(Game1.dialogueFont.MeasureString(prepStr).X / 2, 0), 0.6f, SpriteEffects.None, 0);

            for (int i = 0; i < Math.Min(spots.Length, prepared.Length); ++i)
            {
                PreparedSpell prep = prepared[i];
                if (prep == null)
                {
                    continue;
                }

                Spell spell = SpellBook.get(prep.SpellId);
                if (spell == null || spell.Icons.Length <= prep.Level || spell.Icons[prep.Level] == null)
                {
                    continue;
                }

                b.Draw(spell.Icons[prep.Level], new Rectangle(spots[i].X, spots[i].Y, 50, 50), Game1.player.canCastSpell(spell, prep.Level) ? Color.White : new Color(128, 128, 128));
            }
        }
Пример #5
0
        /// <summary>Raised after drawing the HUD (item toolbar, clock, etc) to the sprite batch, but before it's rendered to the screen. The vanilla HUD may be hidden at this point (e.g. because a menu is open).</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        public static void onRenderedHud(object sender, RenderedHudEventArgs e)
        {
            if (Game1.activeClickableMenu != null || Game1.eventUp || Game1.player.getMaxMana() == 0)
            {
                return;
            }

            SpriteBatch b = e.SpriteBatch;

            Vector2 manaPos = new Vector2(20, Game1.viewport.Height - 56 * 4 - 20);

            bool hasFifthSpellSlot = Game1.player.HasCustomProfession(Skill.ProfessionFifthSpellSlot);

            int spotYAffector = -1;

            if (hasFifthSpellSlot)
            {
                spotYAffector = 0;
            }
            Point[] spots =
                new Point[5]/*
                             * {
                             * new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 40, Game1.viewport.Height - 20 - 50 - 30 - 50 - 25),
                             * new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 50 + 30, Game1.viewport.Height - 20 - 50 - 40 - 25),
                             * new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 40, Game1.viewport.Height - 20 - 50 - 25 ),
                             * new Point((int)manaPos.X + manaBg.Width * 4 + 20, Game1.viewport.Height - 20 - 50 - 40 - 25 ),
                             * };*/
            {
                new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 60 * 0, Game1.viewport.Height - 20 - 50 - 60 * (4 + spotYAffector)),
                new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 60 * 0, Game1.viewport.Height - 20 - 50 - 60 * (3 + spotYAffector)),
                new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 60 * 0, Game1.viewport.Height - 20 - 50 - 60 * (2 + spotYAffector)),
                new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 60 * 0, Game1.viewport.Height - 20 - 50 - 60 * (1 + spotYAffector)),
                new Point((int)manaPos.X + manaBg.Width * 4 + 20 + 60 * 0, Game1.viewport.Height - 20 - 50 - 60 * (0 + spotYAffector)),
            };

            SpellBook book = Game1.player.getSpellBook();

            if (book == null || book.selectedPrepared >= book.prepared.Length)
            {
                return;
            }
            PreparedSpell[] prepared = book.getPreparedSpells();

            for (int i = 0; i < (hasFifthSpellSlot ? 5 : 4); ++i)
            {
                b.Draw(spellBg, new Rectangle(spots[i].X, spots[i].Y, 50, 50), Color.White);
            }

            string prepStr = (book.selectedPrepared + 1) + "/" + book.prepared.Length;

            b.DrawString(Game1.dialogueFont, prepStr, new Vector2(spots[Game1.down].X + 25 + 2, spots[Game1.up].Y - 35 + 0), Color.Black, 0, new Vector2(Game1.dialogueFont.MeasureString(prepStr).X / 2, 0), 0.6f, SpriteEffects.None, 0);
            b.DrawString(Game1.dialogueFont, prepStr, new Vector2(spots[Game1.down].X + 25 - 2, spots[Game1.up].Y - 35 + 0), Color.Black, 0, new Vector2(Game1.dialogueFont.MeasureString(prepStr).X / 2, 0), 0.6f, SpriteEffects.None, 0);
            b.DrawString(Game1.dialogueFont, prepStr, new Vector2(spots[Game1.down].X + 25 + 0, spots[Game1.up].Y - 35 + 2), Color.Black, 0, new Vector2(Game1.dialogueFont.MeasureString(prepStr).X / 2, 0), 0.6f, SpriteEffects.None, 0);
            b.DrawString(Game1.dialogueFont, prepStr, new Vector2(spots[Game1.down].X + 25 + 0, spots[Game1.up].Y - 35 - 2), Color.Black, 0, new Vector2(Game1.dialogueFont.MeasureString(prepStr).X / 2, 0), 0.6f, SpriteEffects.None, 0);
            b.DrawString(Game1.dialogueFont, prepStr, new Vector2(spots[Game1.down].X + 25, spots[Game1.up].Y - 35), Color.White, 0, new Vector2(Game1.dialogueFont.MeasureString(prepStr).X / 2, 0), 0.6f, SpriteEffects.None, 0);

            for (int i = 0; i < (hasFifthSpellSlot ? 5 : 4); ++i)
            {
                if (i >= prepared.Length)
                {
                    break;
                }

                PreparedSpell prep = prepared[i];
                if (prep == null)
                {
                    continue;
                }

                Spell spell = SpellBook.get(prep.SpellId);
                if (spell == null || spell.Icons.Length <= prep.Level || spell.Icons[prep.Level] == null)
                {
                    continue;
                }

                b.Draw(spell.Icons[prep.Level], new Rectangle(spots[i].X, spots[i].Y, 50, 50), Game1.player.canCastSpell(spell, prep.Level) ? Color.White : new Color(128, 128, 128));
            }
        }
Пример #6
0
        private static void onKeyPress(object sender, EventArgsInput args)
        {
            if (args.Button == Config.Key_Cast)
            {
                castPressed = true;
            }

            if (Data == null || Game1.activeClickableMenu != null)
            {
                return;
            }
            if (args.Button == Config.Key_SwapSpells)
            {
                Game1.player.getSpellBook().swapPreparedSet();
            }
            else if (castPressed &&
                     (args.Button == Config.Key_Spell1 || args.Button == Config.Key_Spell2 ||
                      args.Button == Config.Key_Spell3 || args.Button == Config.Key_Spell4))
            {
                int slot = 0;
                if (args.Button == Config.Key_Spell1)
                {
                    slot = 0;
                }
                else if (args.Button == Config.Key_Spell2)
                {
                    slot = 1;
                }
                else if (args.Button == Config.Key_Spell3)
                {
                    slot = 2;
                }
                else if (args.Button == Config.Key_Spell4)
                {
                    slot = 3;
                }

                args.SuppressButton();

                SpellBook       book     = Game1.player.getSpellBook();
                PreparedSpell[] prepared = book.getPreparedSpells();
                if (prepared[slot] == null)
                {
                    return;
                }
                PreparedSpell prep = prepared[slot];

                Spell toCast = SpellBook.get(prep.SpellId);
                if (toCast == null)
                {
                    return;
                }

                //Log.trace("MEOW " + prep.SpellId + " " + prep.Level + " " + Game1.player.canCastSpell(toCast, prep.Level));
                if (Game1.player.canCastSpell(toCast, prep.Level))
                {
                    Log.trace("Casting " + prep.SpellId);
                    Game1.player.castSpell(toCast, prep.Level);
                    Game1.player.addMana(-toCast.getManaCost(Game1.player, prep.Level));
                }
            }
        }