Ejemplo n.º 1
0
        public Item Dequip( Inventory inv, bool discard )
        {
            if( equipped == null ) {
                return null;
            }

            if (!discard) inv.AddItem( equipped, 1 );

            Item i = equipped;
            equipped = null;
            return i;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            _.init( this );
            main_assembly = System.Reflection.Assembly.GetExecutingAssembly(); // tell the library where to find map scripts
            global = new SullyGlobalScripts(this);

            SkillType.initSkillTypes();
            Klass.initClasses();
            PartyData.InitializePartyData();

            Element.initElements();
            Status.initStatuses();

            Skill.initSkills();
            Item.initItems();

            Enemy.initEnemies();

            init_audio();

            mcg = new McGrenderStack();
            mcg.AddLayer( "menu" );
            mcg.AddLayer( "textbox" );
            mcg.AddLayer( "battle_background" );
            mcg.AddLayer( "battle_sprites" );
            mcg.AddLayer( "battle_ui" );
            this.setMcGrender( mcg );

            this.game_input_handler = () => {

                if( this.mainMenu.CanSummonMenu() && action.menu.pressed ) {
                    this.mainMenu.SummonMenu();
                }

                if( this.mainMenu.IsInMenu() ) {
                    this.mainMenu.HandleInput( dir, action );
                }

                if( mainMenu.IsInMenu() ) {
                    return false;
                }

                return true;
            };

            Battle.LoadBackgrounds( Content );

            boxcolors = new Color[3];
            boxcolors[0] = new Color( 0, 0, 0 );
            boxcolors[1] = new Color( 112, 112, 112 );
            boxcolors[2] = new Color( 144, 144, 144 );

            menuColor = new Color( 128,0,128 );

            inventory = new Inventory();
            saves = new SaveManager(this);

            Random random = new Random();
            foreach( String key in Item.masterItemList.Keys ) {
                inventory.AddItem( Item.masterItemList[key], random.Next( 1, 98 ) );
            }

            saves = new SaveManager(this);

            base.Initialize();
        }
Ejemplo n.º 3
0
        public MainMenu()
        {
            Color[] boxcolors = new Color[3];
            boxcolors[0] = new Color( 0, 0, 0 );
            boxcolors[1] = new Color( 112, 112, 112 );
            boxcolors[2] = new Color( 144, 144, 144 );

            activeBgColor = new Texture2D( _.sg.GraphicsDevice, 1, 1, false, SurfaceFormat.Color );
            activeBgColor.SetData(new[] { new Color(140, 0, 140) });

            inactiveBgColor = new Texture2D( _.sg.GraphicsDevice, 1, 1, false, SurfaceFormat.Color );
            inactiveBgColor.SetData(new[] { new Color(0, 0, 0) });

            ControlDelegate cd1 = ( DirectionalButtons dir, VERGEActions action ) => {
                if( commandBox.child != null ) {
                    commandBox.child.OnControlUpdate( dir, action );
                } else {
                    throw new System.InvalidOperationException( "The commandbox is always supposed to have a child set." );
                }
            };

            ControlDelegate updateCommand = ( DirectionalButtons dir, VERGEActions action ) => {
                if( action.cancel.pressed ) {
                    DismissMenu();
                }

                if( action.confirm.pressed ) {
                    mainBox.child = activeMenu = menus[menuOrder[commandBox.cursor]];

                    /// turn on the partyCursor. (-1 is the off state.)
                    if( activeMenu.has_party_select ) {
                        this.partyCursor = 0;
                        activeMenu.cursor = -1;
                    }

                    highlightedMenu = mainBox;
                }

                if( dir.up.DelayPress() ) {
                    commandBox.cursor--;
                    if( commandBox.cursor < 0 ) commandBox.cursor = 5;
                } else if( dir.down.DelayPress() ) {
                    commandBox.cursor++;
                    if( commandBox.cursor > 5 ) commandBox.cursor = 0;
                }
            };

            SullyGame game = _.sg;

            RenderDelegate drawMainbox = ( int x, int y ) => {

                int mainBoxMarginX = 8;
                int mainBoxMarginY = 5;

                mainBox.UpdateBounds( x, y );

                game.spritebatch.Draw( GetHighlightBg(highlightedMenu == mainBox), mainBox.color_bounds, Color.White * .5f );
                game.spritebatch.Draw( mainBox.image, mainBox.bounds, Color.White );

                if( mainBox.child != null ) {
                    mainBox.child.OnDraw( x + mainBoxMarginX, y + mainBoxMarginY );
                } else {

                }
            };

            RenderDelegate drawCommandbox = ( int x, int y ) => {
                commandBox.UpdateBounds( x, y );
                game.spritebatch.Draw(GetHighlightBg(highlightedMenu == commandBox), commandBox.color_bounds, Color.White * .5f);
                game.spritebatch.Draw( commandBox.image, commandBox.bounds, Color.White );

                int mx = 15;
                int my = 15;
                int yOffs = 5;
                int mi = 0;

                commandBox.PrintText( ">", mx - 10, yOffs + my * commandBox.cursor );

                for( int i = 0; i < menuOrder.Length; i++ ) {
                    commandBox.PrintText( menuOrder[i], mx, yOffs + my * mi++ );
                }
            };

            RenderDelegate drawSmallbox = ( int x, int y ) => {

                smallBox.UpdateBounds( x, y );
                game.spritebatch.Draw( GetHighlightBg(highlightedMenu == commandBox), smallBox.color_bounds, Color.White * .5f );
                game.spritebatch.Draw( smallBox.image, smallBox.bounds, Color.White );

                int y1 = 0;
                string m = "" + _.sg.getMoney();

                smallBox.PrintText( "Clams:", 6, y1 ); y1 += 10;
                smallBox.PrintTextRight( m, 61, y1 ); y1 += 20;
                smallBox.PrintText( MainMenu.getFormattedTime(_.sg.stopWatch.Elapsed), 6, y1 );
            };

            mainBox = new MenuBox( _.MakeBox( 220, 220, boxcolors ), 10, 10, -220, 10, cd1, drawMainbox );
            commandBox = new MenuBox( _.MakeBox( 70, 160, boxcolors ), 240, 10, 320, 10, updateCommand, drawCommandbox );
            smallBox = new MenuBox( _.MakeBox( 70, 50, boxcolors ), 240,180, 320, 180, null, drawSmallbox );

            this.activeMenu = this.commandBox;
            this.highlightedMenu = this.commandBox;
            state = MenuState.Active;

            menuOrder = new String[6];
            menuOrder[0] = "ITEM";
            menuOrder[1] = "SKILL";
            menuOrder[2] = "EQUIP";
            menuOrder[3] = "STATUS";
            menuOrder[4] = "OPTION";
            menuOrder[5] = "SAVE";

            RenderDelegate drawItem = ( int x, int y ) => {

                int menu_start = 0;
                if( menu_start + 9 < itemBox.cursor ) {
                    menu_start = itemBox.cursor - 9;
                } else if( menu_start > itemBox.cursor && itemBox.cursor >= 0 ) {
                    menu_start = itemBox.cursor - 1;
                }

                itemBox.PrintText( "Supply", 20, 18, ( itemSubmenu == 0 ) ? Color.White : Color.DarkGray );
                itemBox.PrintText( "Equip", 100, 18, ( itemSubmenu == 1 ) ? Color.White : Color.DarkGray );
                itemBox.PrintText( "Key", 186, 18, ( itemSubmenu == 2 ) ? Color.White : Color.DarkGray );

                int _x = x;
                int _y = y + 20;

                int displayNumber = 10;

                List<ItemSlot> curInv = _.sg.inventory.consumables;
                switch( itemSubmenu ) {
                    case 0:
                        curInv = _.sg.inventory.consumables;
                        break;
                    case 1:
                        curInv = _.sg.inventory.equipment;
                        break;
                    case 2:
                        curInv = _.sg.inventory.key;
                        break;
                }

                if( curInv.Count == 0 ) {

                    itemBox.MenuDrawSubWindow( game.GraphicsDevice, _x, _y, _x + 200, _y + 180, itemBox.cursor, 13, 1, 0, 0 );

                    itemBox.PrintText( "No items.", _x + 32, _y );

                } else {

                    itemBox.MenuDrawSubWindow(game.GraphicsDevice, _x, _y, _x + 200, _y + 150, itemBox.cursor, lineSize, curInv.Count, menu_start, 4);

                    _y += 4;

                    itemBox.DrawItemList( _x, _y, lineSize, menu_start, displayNumber, curInv, true );

                    int j = itemBox.cursor;

                    itemBox.PrintManyText( _.autotext(curInv[j].item.description, 190), _x, _y + 142 );
                }
            };

            RenderDelegate drawSkill = ( int x, int y ) => {
                itemBox.PrintText( "Skill...", x, y );
            };

            RenderDelegate drawOption = ( int x, int y ) => {
                itemBox.PrintText( "Option...", x, y );
            };

            RenderDelegate drawSave = ( int x, int y ) => {
                itemBox.PrintText( "Save...", x, y );
            };

            RenderDelegate drawParty = ( int x, int y ) => {

                int i = 0;
                foreach( PartyMember pm in _.sg.party.getMembers() ) {
                    int _y = y + ( 43 * i );
                    int _x = x - 8;

                    if( this.partyCursor == i ) {
                        partyBox.PrintText( ">", x-3, _y );
                    }

                    Color lightColor = ( this.partyCursor >= 0 && this.partyCursor == i ) ? Color.White : Color.DarkGray;
                    Color darkColor = ( this.partyCursor >= 0 && this.partyCursor == i ) ? Color.LightGray : Color.DarkGray;

                    pm.ent.DrawAt(x + pm.ent.hitbox.X - pm.ent.destination.X, _y + pm.ent.hitbox.Y - pm.ent.destination.Y, 0);
                    partyBox.PrintText( pm.name, _x + 32, _y, lightColor );
                    partyBox.PrintText( pm.klass.name, _x + 90, _y, darkColor );
                    partyBox.PrintTextRight( "LV.    ", x + 200, _y, darkColor );
                    partyBox.PrintTextRight( "" + pm.level, x + 200, _y, darkColor );

                    partyBox.PrintText( "HP: " + pm.cur_hp + "/" + pm.getStat( Stat.HP ), _x + 33, _y + 10, lightColor );
                    partyBox.PrintText( "MP: " + pm.cur_mp + "/" + pm.getStat( Stat.MP ), _x + 32, _y + 20, lightColor );

                    i++;
                }
            };

            RenderDelegate _drawStatusTop = ( int _x, int _y ) => {
                Stat s;
                PartyMember pm = _.sg.party.getMembers()[this.partyCursor];
                pm.ent.DrawAt(_x + pm.ent.hitbox.X - pm.ent.destination.X, _y + pm.ent.hitbox.Y - pm.ent.destination.Y, 0);
                statusBox.PrintText( pm.name, _x + 24, _y );
                statusBox.PrintText( pm.klass.name, _x + 32, _y + 12 );

                statusBox.PrintText( "Level:", _x + 112, _y ); statusBox.PrintTextRight( "" + pm.level, _x + 190, _y );
                statusBox.PrintText( "HP:", _x + 112, _y + 12 ); statusBox.PrintTextRight( "" + pm.cur_hp + "/" + pm.getStat( Stat.HP ), _x + 190, _y + 12 );
                statusBox.PrintText( "MP:", _x + 112, _y + 24 ); statusBox.PrintTextRight( "" + pm.cur_mp + "/" + pm.getStat( Stat.MP ), _x + 190, _y + 24 );

                //
                if( pretendEquipItem == null ) {
                    for (int i = 0; i < PartyMember.NUM_STATS; i++ ) {
                        s = (Stat)i;
                        statusBox.MenuPrintStat(_x + 8, _y + 4, s, pm.getStat(s), Color.White);
                    }
                } else {

                    for (int i = 0; i < PartyMember.NUM_STATS; i++) {
                        s = (Stat)i;
                        int ps = pm.getPretendStat( s, pretendEquipSlotName, this.pretendEquipItem );
                        int rs = pm.getStat( s );

                        if( ps > rs ) {
                            statusBox.MenuPrintStat( _x + 8, _y + 4, s, ps, Color.LimeGreen );
                        } else if( ps < rs ) {
                            statusBox.MenuPrintStat( _x + 8, _y + 4, s, ps, Color.Red );
                        } else {
                            statusBox.MenuPrintStat( _x + 8, _y + 4, s, ps, Color.White );
                        }
                    }
                }
            };

            RenderDelegate drawEquip = ( int x, int y ) => {

                PartyMember pm = _.sg.party.getMembers()[this.partyCursor];

                int _x = x + 4;
                int _y = y + 4;

                _drawStatusTop( _x, _y );

                if( equipSlotSubmenu < 0 ) {

                    for( int i = 0; i < PartyMember.equipment_slot_order.Length; i++ ) {

                        equipBox.PrintText( PartyMember.equipment_slot_order[i].ToUpper(), _x + 8, _y + 94 + ( i * 12 ) );

                        Item item = pm.equipment[PartyMember.equipment_slot_order[i]].getItem();
                        if( item != null ) {
                            equipBox.PrintText( item.name, _x + 72, _y + 94 + ( i * 12 ) );
                        } else {
                            equipBox.PrintText( "(none)", _x + 72, _y + 94 + ( i * 12 ), Color.DarkGray );
                        }
                    }

                    if( equipBox.cursor < 0 ) equipBox.cursor = 0;
                    equipBox.PrintText( ">", _x, _y + 94 + ( equipBox.cursor * 12 ) );

                    Item curItem = pm.equipment[PartyMember.equipment_slot_order[equipBox.cursor]].getItem();
                    if( curItem != null ) {
                        equipBox.PrintManyText( _.autotext( curItem.description, 190 ), _x, _y + 153 );
                    } else {
                        equipBox.PrintText( "No item equipped.", _x, _y + 160, Color.DarkGray );
                    }
                } else {
                    int menu_start = 0;
                    if( menu_start + 3 < equipBox.cursor ) {
                        menu_start = equipBox.cursor - 3;
                    } else if( menu_start > equipBox.cursor && equipBox.cursor >= 0 ) {
                        menu_start = equipBox.cursor - 1;
                    }

                    equipBox.MenuDrawSubWindow(game.GraphicsDevice, _x, _y + 93, _x + 200, _y + 151, equipBox.cursor, lineSize, subEquipment.equipment.Count, menu_start, 4);

                    equipBox.DrawItemList( _x, _y + 93, lineSize, menu_start, 4, subEquipment.equipment, false );

                    equipBox.PrintManyText( _.autotext( subEquipment.equipment[equipBox.cursor].item.description, 190 ), _x, _y + 153 );
                }
            };

            RenderDelegate drawStatus = ( int x, int y ) => {

                if( this.partyCursor >= 0 && this.partyCursor == statusBox.cursor ) {

                    PartyMember pm = _.sg.party.getMembers()[this.partyCursor];

                    int _x = x + 4;
                    int _y = y + 4;

                    _drawStatusTop( _x, _y );

                    statusBox.PrintText( "EXP " + pm.cur_xp, _x + 8, _y + 100 );
                    statusBox.PrintText( "NEXT " + pm.getXpUntilNextLevel(), _x + 104, _y + 100 );

                    equipBox.PrintManyText( _.autotext( pm.description, 190 ), _x, _y + 170 );

                } else {
                    drawParty( x, y );
                }
            };

            ControlDelegate updatePartySelect = ( DirectionalButtons dir, VERGEActions action ) => {

                int partySize = _.sg.party.getMembers().Length;

                if( dir.up.DelayPress() || dir.left.DelayPress() ) {
                    this.partyCursor--;
                    if( this.partyCursor < 0 ) this.partyCursor = partySize - 1;
                } else if( dir.down.DelayPress() || dir.right.DelayPress() ) {
                    this.partyCursor++;
                    if( this.partyCursor >= partySize ) this.partyCursor = 0;
                }
            };

            ControlDelegate updateItem = ( DirectionalButtons dir, VERGEActions action ) => {
                if( action.cancel.pressed ) {
                    LeaveMainMenu();
                }

                int menuMax = 0;
                switch( itemSubmenu ) {
                    case 0:
                        menuMax = _.sg.inventory.consumables.Count;
                        break;
                    case 1:
                        menuMax = _.sg.inventory.equipment.Count;
                        break;
                    case 2:
                        menuMax = _.sg.inventory.key.Count;
                        break;
                }

                if( dir.up.DelayPress() ) {
                    itemBox.cursor--;
                    if( itemBox.cursor < 0 ) itemBox.cursor = menuMax-1;
                } else if( dir.down.DelayPress() ) {
                    itemBox.cursor++;
                    if( itemBox.cursor >= menuMax ) itemBox.cursor = 0;
                }

                if( dir.left.DelayPress() ) {
                    itemSubmenu--;
                    itemBox.cursor = 0;
                    if( itemSubmenu < 0 ) itemSubmenu = 2;
                } else if( dir.right.DelayPress() ) {
                    itemSubmenu++;
                    itemBox.cursor = 0;
                    if( itemSubmenu > 2 ) itemSubmenu = 0;
                }

            };

            ControlDelegate updateSkill = ( DirectionalButtons dir, VERGEActions action ) => {
                if( action.cancel.pressed ) {
                    LeaveMainMenu();
                }
            };

            ControlDelegate updateEquip = ( DirectionalButtons dir, VERGEActions action ) => {

                if( equipSlotSubmenu < 0 ) {
                    if( action.cancel.pressed ) {
                        LeaveMainMenu();
                    }

                    if( equipBox.cursor < 0 ) {
                        equipBox.cursor = 0;
                    }

                    if( dir.up.DelayPress() ) {
                        equipBox.cursor--;
                        if( equipBox.cursor < 0 ) equipBox.cursor = PartyMember.equipment_slot_order.Length - 1;
                    } else if( dir.down.DelayPress() ) {
                        equipBox.cursor++;
                        if( equipBox.cursor >= PartyMember.equipment_slot_order.Length ) equipBox.cursor = 0;
                    }

                    if( action.confirm.pressed ) {
                        equipSlotSubmenu = equipBox.cursor;
                        equipBox.cursor = 0;

                        PartyMember pm = _.sg.party.getMembers()[this.partyCursor];

                        pretendEquipSlotName = PartyMember.equipment_slot_order[equipSlotSubmenu];

                        subEquipment = _.sg.inventory.GetWearableEquipmentSet(
                            pm.klass,
                            pm.equipment[pretendEquipSlotName].getSlotType()
                        );
                    }

                } else {

                    if( action.cancel.pressed ) {
                        equipBox.cursor = equipSlotSubmenu;
                        equipSlotSubmenu = -1;
                        subEquipment = null;
                        pretendEquipSlotName = "";
                        pretendEquipItem = null;

                    } else {
                        if( dir.up.DelayPress() ) {
                            equipBox.cursor--;
                            if( equipBox.cursor < 0 ) equipBox.cursor = subEquipment.equipment.Count - 1;
                        } else if( dir.down.DelayPress() ) {
                            equipBox.cursor++;
                            if( equipBox.cursor >= subEquipment.equipment.Count ) equipBox.cursor = 0;
                        }

                        pretendEquipItem = subEquipment.equipment[equipBox.cursor].item;

                        if( action.confirm.pressed ) {

                            PartyMember pm = _.sg.party.getMembers()[this.partyCursor];
                            pm.equipment[PartyMember.equipment_slot_order[equipSlotSubmenu]].Dequip( _.sg.inventory );

                            if( subEquipment.equipment[equipBox.cursor].item != Item.none ) {
                                pm.equipment[PartyMember.equipment_slot_order[equipSlotSubmenu]].Equip( subEquipment.equipment[equipBox.cursor].item, _.sg.inventory );
                            }

                            equipBox.cursor = equipSlotSubmenu;
                            equipSlotSubmenu = -1;
                            subEquipment = null;
                            pretendEquipSlotName = "";
                            pretendEquipItem = null;
                        }
                    }
                }
            };

            ControlDelegate updateStatus = ( DirectionalButtons dir, VERGEActions action ) => {

                if( this.partyCursor >= 0 && statusBox.cursor < 0 ) {

                    updatePartySelect( dir, action );

                    if( action.confirm.pressed ) {
                        statusBox.cursor = this.partyCursor;
                    }

                    if( action.cancel.pressed ) {
                        LeaveMainMenu();
                    }

                } else {
                    if( action.cancel.pressed ) {
                        statusBox.cursor = -1;
                    }
                }
            };

            ControlDelegate updateOption = ( DirectionalButtons dir, VERGEActions action ) => {
                if( action.cancel.pressed ) {
                    LeaveMainMenu();
                }
            };

            ControlDelegate updateSave = ( DirectionalButtons dir, VERGEActions action ) => {
                if( action.cancel.pressed ) {
                    LeaveMainMenu();
                }
            };

            ControlDelegate updateParty = ( DirectionalButtons dir, VERGEActions action ) => {
                if( action.cancel.pressed ) {
                    LeaveMainMenu();
                }
            };

            itemBox = new MenuBox(updateItem, drawItem );
            skillBox = new MenuBox( updateSkill, drawSkill );
            equipBox = new MenuBox( updateEquip, drawEquip );
            statusBox = new MenuBox( updateStatus, drawStatus );
            optionBox = new MenuBox( updateOption, drawOption );
            saveBox = new MenuBox( updateSave, drawSave );

            skillBox.has_party_select = true;
            equipBox.has_party_select = true;
            statusBox.has_party_select = true;

            menus[menuOrder[0]] = itemBox;
            menus[menuOrder[1]] = skillBox;
            menus[menuOrder[2]] = equipBox;
            menus[menuOrder[3]] = statusBox;
            menus[menuOrder[4]] = optionBox;
            menus[menuOrder[5]] = saveBox;

            partyBox = new MenuBox( updateParty, drawParty );
            mainBox.child = partyBox;
        }
Ejemplo n.º 4
0
        public void Equip(Item i, Inventory inv, bool force)
        {
            if(!force && equipped != null ) {
                throw new Exception( "Tried to equip ("+i.name+") without first removing ("+equipped.name+")" );
            }

            if( i.type != ItemType.Equipment ) {
                throw new Exception( "Tried to equip a non-equipment." );
            }

            inv.TakeItem( i, 1 );

            equipped = i;
        }
Ejemplo n.º 5
0
 public void Equip(string name, Inventory inv, bool force)
 {
     Equip(Item.masterItemList[name.ToLower()], inv, force);
 }
Ejemplo n.º 6
0
 public void Equip(Item i, Inventory inv)
 {
     Equip(i, inv, false);
 }
Ejemplo n.º 7
0
 // Removes an item. If discard = true, the item will be destroyed rather than sent to inventory!
 public Item Dequip(Inventory inv)
 {
     return Dequip(inv, false);
 }
Ejemplo n.º 8
0
        public Inventory GetWearableEquipmentSet( Klass klass, EquipSlotType slot )
        {
            Inventory ret = new Inventory();

            foreach( ItemSlot sl in this.equipment ) {
                if( sl.item.equip_slot == slot && sl.item.equip_classes.Contains( klass ) ) {
                    ret.AddItem( sl.item, sl.quant );
                }
            }

            if( slot != EquipSlotType.RightHand && slot != EquipSlotType.Body ) { // can't unequip from RH or Body slots
                ret.AddItem( Item.none, 1 );
            }

            return ret;
        }