public void Update() { if (Globals.Bank[mMySlot].ItemId != mCurrentItemId) { mCurrentItemId = Globals.Bank[mMySlot].ItemId; var item = ItemBase.Get(Globals.Bank[mMySlot].ItemId); if (item != null) { var itemTex = Globals.ContentManager.GetTexture(GameContentManager.TextureType.Item, item.Icon); if (itemTex != null) { Pnl.Texture = itemTex; Pnl.RenderColor = item.Color; } else { if (Pnl.Texture != null) { Pnl.Texture = null; } } } else { if (Pnl.Texture != null) { Pnl.Texture = null; } } } if (!IsDragging) { if (mMouseOver) { if (!Globals.InputManager.MouseButtonDown(GameInput.MouseButtons.Left)) { mCanDrag = true; mMouseX = -1; mMouseY = -1; if (Globals.System.GetTimeMs() < mClickTime) { //Globals.Me.TryUseItem(_mySlot); mClickTime = 0; } } else { if (mCanDrag && Draggable.Active == null) { if (mMouseX == -1 || mMouseY == -1) { mMouseX = InputHandler.MousePosition.X - Pnl.LocalPosToCanvas(new Point(0, 0)).X; mMouseY = InputHandler.MousePosition.Y - Pnl.LocalPosToCanvas(new Point(0, 0)).Y; } else { var xdiff = mMouseX - (InputHandler.MousePosition.X - Pnl.LocalPosToCanvas(new Point(0, 0)).X); var ydiff = mMouseY - (InputHandler.MousePosition.Y - Pnl.LocalPosToCanvas(new Point(0, 0)).Y); if (Math.Sqrt(Math.Pow(xdiff, 2) + Math.Pow(ydiff, 2)) > 5) { IsDragging = true; mDragIcon = new Draggable( Pnl.LocalPosToCanvas(new Point(0, 0)).X + mMouseX, Pnl.LocalPosToCanvas(new Point(0, 0)).X + mMouseY, Pnl.Texture ); } } } } } } else { if (mDragIcon.Update()) { //Drug the item and now we stopped IsDragging = false; var dragRect = new FloatRect( mDragIcon.X - sItemXPadding / 2, mDragIcon.Y - sItemYPadding / 2, sItemXPadding / 2 + 32, sItemYPadding / 2 + 32 ); float bestIntersect = 0; var bestIntersectIndex = -1; //So we picked up an item and then dropped it. Lets see where we dropped it to. //Check inventory first. if (mBankWindow.RenderBounds().IntersectsWith(dragRect)) { for (var i = 0; i < Options.MaxBankSlots; i++) { if (mBankWindow.Items[i].RenderBounds().IntersectsWith(dragRect)) { if (FloatRect.Intersect(mBankWindow.Items[i].RenderBounds(), dragRect).Width * FloatRect.Intersect(mBankWindow.Items[i].RenderBounds(), dragRect).Height > bestIntersect) { bestIntersect = FloatRect.Intersect(mBankWindow.Items[i].RenderBounds(), dragRect).Width * FloatRect.Intersect(mBankWindow.Items[i].RenderBounds(), dragRect).Height; bestIntersectIndex = i; } } } if (bestIntersectIndex > -1) { if (mMySlot != bestIntersectIndex) { //Try to swap.... PacketSender.SendMoveBankItems(bestIntersectIndex, mMySlot); //Globals.Me.SwapItems(bestIntersectIndex, _mySlot); } } } mDragIcon.Dispose(); } } }
public void SpawnResourceItems(Entity killer) { //Find tile to spawn items var tiles = new List <TileHelper>(); for (var x = X - 1; x <= X + 1; x++) { for (var y = Y - 1; y <= Y + 1; y++) { var tileHelper = new TileHelper(MapId, x, y); if (tileHelper.TryFix()) { //Tile is valid.. let's see if its open var map = MapInstance.Get(tileHelper.GetMapId()); if (map != null) { if (!map.TileBlocked(tileHelper.GetX(), tileHelper.GetY())) { tiles.Add(tileHelper); } else { if (killer.MapId == tileHelper.GetMapId() && killer.X == tileHelper.GetX() && killer.Y == tileHelper.GetY()) { tiles.Add(tileHelper); } } } } } } if (tiles.Count > 0) { TileHelper selectedTile = null; //Prefer the players tile, otherwise choose randomly for (var i = 0; i < tiles.Count; i++) { if (tiles[i].GetMapId() == killer.MapId && tiles[i].GetX() == killer.X && tiles[i].GetY() == killer.Y) { selectedTile = tiles[i]; } } if (selectedTile == null) { selectedTile = tiles[Randomization.Next(0, tiles.Count)]; } // Drop items foreach (var item in Items) { if (ItemBase.Get(item.ItemId) != null) { MapInstance.Get(selectedTile.GetMapId()) .SpawnItem(selectedTile.GetX(), selectedTile.GetY(), item, item.Quantity, killer.Id); } } } Items.Clear(); }
//Methods public void Update() { if (mCharacterWindow.IsHidden) { return; } mCharacterName.Text = Globals.Me.Name; mCharacterLevelAndClass.Text = Strings.Character.levelandclass.ToString( Globals.Me.Level, ClassBase.GetName(Globals.Me.Class) ); //Load Portrait //UNCOMMENT THIS LINE IF YOU'D RATHER HAVE A FACE HERE GameTexture faceTex = Globals.ContentManager.GetTexture(GameContentManager.TextureType.Face, Globals.Me.Face); var entityTex = Globals.ContentManager.GetTexture( GameContentManager.TextureType.Entity, Globals.Me.MySprite ); /* UNCOMMENT THIS BLOCK IF YOU"D RATHER HAVE A FACE HERE if (Globals.Me.Face != "" && Globals.Me.Face != _currentSprite && faceTex != null) * { * _characterPortrait.Texture = faceTex; * _characterPortrait.SetTextureRect(0, 0, faceTex.GetWidth(), faceTex.GetHeight()); * _characterPortrait.SizeToContents(); * Align.Center(_characterPortrait); * _characterPortrait.IsHidden = false; * for (int i = 0; i < Options.EquipmentSlots.Count; i++) * { * _paperdollPanels[i].Hide(); * } * } * else */ if (Globals.Me.MySprite != "" && Globals.Me.MySprite != mCurrentSprite && entityTex != null) { for (var z = 0; z < Options.PaperdollOrder[1].Count; z++) { var paperdoll = ""; if (Options.EquipmentSlots.IndexOf(Options.PaperdollOrder[1][z]) > -1) { var equipment = Globals.Me.MyEquipment; if (equipment[Options.EquipmentSlots.IndexOf(Options.PaperdollOrder[1][z])] > -1 && equipment[Options.EquipmentSlots.IndexOf(Options.PaperdollOrder[1][z])] < Options.MaxInvItems) { var itemNum = Globals.Me .Inventory[equipment[Options.EquipmentSlots.IndexOf(Options.PaperdollOrder[1][z])]] .ItemId; if (ItemBase.Get(itemNum) != null) { var itemdata = ItemBase.Get(itemNum); if (Globals.Me.Gender == 0) { paperdoll = itemdata.MalePaperdoll; } else { paperdoll = itemdata.FemalePaperdoll; } } } } else if (Options.PaperdollOrder[1][z] == "Player") { PaperdollPanels[z].Show(); PaperdollPanels[z].Texture = entityTex; PaperdollPanels[z].SetTextureRect(0, 0, entityTex.GetWidth() / Options.Instance.Sprites.NormalFrames, entityTex.GetHeight() / Options.Instance.Sprites.Directions); PaperdollPanels[z].SizeToContents(); PaperdollPanels[z].RenderColor = Globals.Me.Color; Align.Center(PaperdollPanels[z]); } if (string.IsNullOrWhiteSpace(paperdoll) && !string.IsNullOrWhiteSpace(PaperdollTextures[z]) && Options.PaperdollOrder[1][z] != "Player") { PaperdollPanels[z].Texture = null; PaperdollPanels[z].Hide(); PaperdollTextures[z] = ""; } else if (paperdoll != "" && paperdoll != PaperdollTextures[z]) { var paperdollTex = Globals.ContentManager.GetTexture( GameContentManager.TextureType.Paperdoll, paperdoll ); PaperdollPanels[z].Texture = paperdollTex; if (paperdollTex != null) { PaperdollPanels[z] .SetTextureRect( 0, 0, PaperdollPanels[z].Texture.GetWidth() / Options.Instance.Sprites.NormalFrames, PaperdollPanels[z].Texture.GetHeight() / Options.Instance.Sprites.Directions ); PaperdollPanels[z] .SetSize( PaperdollPanels[z].Texture.GetWidth() / Options.Instance.Sprites.NormalFrames, PaperdollPanels[z].Texture.GetHeight() / Options.Instance.Sprites.Directions ); PaperdollPanels[z] .SetPosition( mCharacterContainer.Width / 2 - PaperdollPanels[z].Width / 2, mCharacterContainer.Height / 2 - PaperdollPanels[z].Height / 2 ); } PaperdollPanels[z].Show(); PaperdollTextures[z] = paperdoll; } } } else if (Globals.Me.MySprite != mCurrentSprite && Globals.Me.Face != mCurrentSprite) { mCharacterPortrait.IsHidden = true; for (var i = 0; i < Options.EquipmentSlots.Count; i++) { PaperdollPanels[i].Hide(); } } mAttackLabel.SetText( Strings.Character.stat0.ToString(Strings.Combat.stat0, Globals.Me.Stat[(int)Stats.Attack]) ); mDefenseLabel.SetText( Strings.Character.stat2.ToString(Strings.Combat.stat2, Globals.Me.Stat[(int)Stats.Defense]) ); mSpeedLabel.SetText( Strings.Character.stat4.ToString(Strings.Combat.stat4, Globals.Me.Stat[(int)Stats.Speed]) ); mAbilityPwrLabel.SetText( Strings.Character.stat1.ToString(Strings.Combat.stat1, Globals.Me.Stat[(int)Stats.AbilityPower]) ); mMagicRstLabel.SetText( Strings.Character.stat3.ToString(Strings.Combat.stat3, Globals.Me.Stat[(int)Stats.MagicResist]) ); mPointsLabel.SetText(Strings.Character.points.ToString(Globals.Me.StatPoints)); mAddAbilityPwrBtn.IsHidden = Globals.Me.StatPoints == 0 || Globals.Me.Stat[(int)Stats.AbilityPower] == Options.MaxStatValue; mAddAttackBtn.IsHidden = Globals.Me.StatPoints == 0 || Globals.Me.Stat[(int)Stats.Attack] == Options.MaxStatValue; mAddDefenseBtn.IsHidden = Globals.Me.StatPoints == 0 || Globals.Me.Stat[(int)Stats.Defense] == Options.MaxStatValue; mAddMagicResistBtn.IsHidden = Globals.Me.StatPoints == 0 || Globals.Me.Stat[(int)Stats.MagicResist] == Options.MaxStatValue; mAddSpeedBtn.IsHidden = Globals.Me.StatPoints == 0 || Globals.Me.Stat[(int)Stats.Speed] == Options.MaxStatValue; for (var i = 0; i < Options.EquipmentSlots.Count; i++) { if (Globals.Me.MyEquipment[i] > -1 && Globals.Me.MyEquipment[i] < Options.MaxInvItems) { if (Globals.Me.Inventory[Globals.Me.MyEquipment[i]].ItemId != Guid.Empty) { Items[i] .Update( Globals.Me.Inventory[Globals.Me.MyEquipment[i]].ItemId, Globals.Me.Inventory[Globals.Me.MyEquipment[i]].StatBuffs ); } else { Items[i].Update(Guid.Empty, mEmptyStatBoost); } } else { Items[i].Update(Guid.Empty, mEmptyStatBoost); } } }
public void InitEditor() { var selectedId = Guid.Empty; var folderNodes = new Dictionary <string, TreeNode>(); if (lstItems.SelectedNode != null && lstItems.SelectedNode.Tag != null) { selectedId = (Guid)lstItems.SelectedNode.Tag; } lstItems.Nodes.Clear(); cmbEquipmentSlot.Items.Clear(); cmbEquipmentSlot.Items.AddRange(Options.EquipmentSlots.ToArray()); cmbToolType.Items.Clear(); cmbToolType.Items.Add(Strings.General.none); cmbToolType.Items.AddRange(Options.ToolTypes.ToArray()); cmbEquipmentBonus.Items.Clear(); for (var i = 0; i < Strings.ItemEditor.bonuseffects.Count; i++) { cmbEquipmentBonus.Items.Add(Strings.ItemEditor.bonuseffects[i]); } cmbProjectile.Items.Clear(); cmbProjectile.Items.Add(Strings.General.none); cmbProjectile.Items.AddRange(ProjectileBase.Names); //Collect folders var mFolders = new List <string>(); foreach (var itm in ItemBase.Lookup) { if (!string.IsNullOrEmpty(((ItemBase)itm.Value).Folder) && !mFolders.Contains(((ItemBase)itm.Value).Folder)) { mFolders.Add(((ItemBase)itm.Value).Folder); if (!mKnownFolders.Contains(((ItemBase)itm.Value).Folder)) { mKnownFolders.Add(((ItemBase)itm.Value).Folder); } } } mFolders.Sort(); mKnownFolders.Sort(); cmbFolder.Items.Clear(); cmbFolder.Items.Add(""); cmbFolder.Items.AddRange(mKnownFolders.ToArray()); lstItems.Sorted = !btnChronological.Checked; if (!btnChronological.Checked && !CustomSearch()) { foreach (var folder in mFolders) { var node = lstItems.Nodes.Add(folder); node.ImageIndex = 0; node.SelectedImageIndex = 0; folderNodes.Add(folder, node); } } foreach (var itm in ItemBase.ItemPairs) { var node = new TreeNode(itm.Value); node.Tag = itm.Key; node.ImageIndex = 1; node.SelectedImageIndex = 1; var folder = ItemBase.Get(itm.Key).Folder; if (!string.IsNullOrEmpty(folder) && !btnChronological.Checked && !CustomSearch()) { var folderNode = folderNodes[folder]; folderNode.Nodes.Add(node); if (itm.Key == selectedId) { folderNode.Expand(); } } else { lstItems.Nodes.Add(node); } if (CustomSearch()) { if (!node.Text.ToLower().Contains(txtSearch.Text.ToLower())) { node.Remove(); } } if (itm.Key == selectedId) { lstItems.SelectedNode = node; } } var selectedNode = lstItems.SelectedNode; if (!btnChronological.Checked) { lstItems.Sort(); } lstItems.SelectedNode = selectedNode; foreach (var node in mExpandedFolders) { if (folderNodes.ContainsKey(node)) { folderNodes[node].Expand(); } } }
//Update the crafting bar public void Update() { if (!mInitialized) { //Quickly Look through the inventory and count the luck stat double luck = 0; foreach (var equip in Globals.Me.Equipment) { if (ItemBase.Get(equip)?.Effect?.Type == EffectType.Luck) { luck += ItemBase.Get(equip).Effect.Percentage; } } var j = 0; for (var i = 0; i < Globals.ActiveCraftingTable?.Crafts?.Count; ++i) { var activeCraft = CraftBase.Get(Globals.ActiveCraftingTable.Crafts[i]); if (activeCraft == null) { continue; } if (!Globals.ActiveCraftingTableReqs.Contains(i + "-")) { j++; var tmpRow = mRecipes?.AddRow(j + ") " + ItemBase.GetName(activeCraft.ItemId) + " (" + Math.Min(activeCraft.SuccessRate + (luck / 10), 100) + "%) "); if (tmpRow == null) { continue; } tmpRow.UserData = Globals.ActiveCraftingTable.Crafts[i]; tmpRow.DoubleClicked += tmpNode_DoubleClicked; tmpRow.Clicked += tmpNode_DoubleClicked; tmpRow.SetTextColor(Color.White); tmpRow.RenderColor = new Color(50, 255, 255, 255); } } //Load the craft data if (Globals.ActiveCraftingTable?.Crafts?.Count > 0) { LoadCraftItems(Globals.ActiveCraftingTable.Crafts[0]); } mInitialized = true; } //We received green light to craft, continue crafting if (Globals.canCraftrq && clickedCraft) { Crafting = true; mBarTimer = Globals.System.GetTimeMs(); PacketSender.SendCraftItem(Globals.canCraftitem); mCraftWindow.IsClosable = false; Globals.canCraftrq = false; Globals.canCraftitem = Guid.Empty; clickedCraft = false; return; } //Uncomment next lines to have the craftbutton disable if requirements are not met /* * if (!Globals.canCraftrq) * { * mCraft.Disable(); * } * * if (Globals.canCraftrq) * { * mCraft.Enable(); * } */ if (!Crafting) { mBar.Width = 0; return; } var craft = CraftBase.Get(mCraftId); if (craft == null) { return; } var delta = Globals.System.GetTimeMs() - mBarTimer; if (delta > craft.Time) { delta = craft.Time; Crafting = false; if (mCraftWindow != null) { mCraftWindow.IsClosable = true; } LoadCraftItems(mCraftId); mBar.Width = 0; } var ratio = craft.Time == 0 ? 0 : Convert.ToDecimal(delta) / Convert.ToDecimal(craft.Time); var width = ratio * mBarContainer?.Width ?? 0; if (mBar == null) { return; } mBar.SetTextureRect( 0, 0, Convert.ToInt32(ratio * mBar.Texture?.GetWidth() ?? 0), mBar.Texture?.GetHeight() ?? 0 ); mBar.Width = Convert.ToInt32(width); }
/// <summary> /// Spawn an item to this map instance. /// </summary> /// <param name="x">The horizontal location of this item</param> /// <param name="y">The vertical location of this item.</param> /// <param name="item">The <see cref="Item"/> to spawn on the map.</param> /// <param name="amount">The amount of times to spawn this item to the map. Set to the <see cref="Item"/> quantity, overwrites quantity if stackable!</param> /// <param name="owner">The player Id that will be the temporary owner of this item.</param> public void SpawnItem(int x, int y, Item item, int amount, Guid owner) { if (item == null) { Log.Warn($"Tried to spawn {amount} of a null item at ({x}, {y}) in map {Id}."); return; } var itemDescriptor = ItemBase.Get(item.ItemId); if (itemDescriptor == null) { Log.Warn($"No item found for {item.ItemId}."); return; } // if we can stack this item or the user configured to drop items consolidated, simply spawn a single stack of it. if (itemDescriptor.Stackable || Options.Loot.ConsolidateMapDrops) { var mapItem = new MapItem(item.ItemId, amount, item.BagId, item.Bag) { X = x, Y = y, DespawnTime = Globals.Timing.Milliseconds + Options.Loot.ItemDespawnTime, Owner = owner, OwnershipTime = Globals.Timing.Milliseconds + Options.Loot.ItemOwnershipTime, VisibleToAll = Options.Loot.ShowUnownedItems }; // If this is a piece of equipment, set up the stat buffs for it. if (itemDescriptor.ItemType == ItemTypes.Equipment) { mapItem.SetupStatBuffs(item); } MapItems.Add(mapItem); PacketSender.SendMapItemUpdate(Id, MapItems.Count - 1); } else { // Oh boy here we go! Set quantity to 1 and drop multiple! for (var i = 0; i < amount; i++) { var mapItem = new MapItem(item.ItemId, amount, item.BagId, item.Bag) { X = x, Y = y, DespawnTime = Globals.Timing.Milliseconds + Options.Loot.ItemDespawnTime, Owner = owner, OwnershipTime = Globals.Timing.Milliseconds + Options.Loot.ItemOwnershipTime, VisibleToAll = Options.Loot.ShowUnownedItems }; // If this is a piece of equipment, set up the stat buffs for it. if (itemDescriptor.ItemType == ItemTypes.Equipment) { mapItem.SetupStatBuffs(item); } MapItems.Add(mapItem); } PacketSender.SendMapItemsToProximity(Id); } }
public void Update() { if (Globals.Me == null) { return; } //See if Label Should be changed if (mHotKey != Controls.ActiveControls.ControlMapping[Control.Hotkey1 + mYindex].Key1) { KeyLabel.SetText( Strings.Keys.keydict[ Enum.GetName( typeof(Keys), Controls.ActiveControls.ControlMapping[Control.Hotkey1 + mYindex].Key1 ) .ToLower()] ); mHotKey = Controls.ActiveControls.ControlMapping[Control.Hotkey1 + mYindex].Key1; } var slot = Globals.Me.Hotbar[mYindex]; var updateDisplay = mCurrentId != slot.ItemOrSpellId || mTexLoaded == false; //Update display if the hotbar item changes or we dont have a texture for the current item if (mCurrentId != slot.ItemOrSpellId) { mCurrentItem = null; mCurrentSpell = null; var itm = ItemBase.Get(slot.ItemOrSpellId); var spl = SpellBase.Get(slot.ItemOrSpellId); if (itm != null) { mCurrentItem = itm; } if (spl != null) { mCurrentSpell = spl; } mCurrentId = slot.ItemOrSpellId; } mSpellBookItem = null; mInventoryItem = null; mInventoryItemIndex = -1; if (mCurrentItem != null) { var itmIndex = Globals.Me.FindHotbarItem(slot); if (itmIndex > -1) { mInventoryItemIndex = itmIndex; mInventoryItem = Globals.Me.Inventory[itmIndex]; } } else if (mCurrentSpell != null) { var splIndex = Globals.Me.FindHotbarSpell(slot); if (splIndex > -1) { mSpellBookItem = Globals.Me.Spells[splIndex]; } } if (mCurrentItem != null) //When it's an item { //We don't have it, and the icon isn't faded if (mInventoryItem == null && !mIsFaded) { updateDisplay = true; } //We have it, and the equip icon doesn't match equipped status if (mInventoryItem != null && Globals.Me.IsEquipped(mInventoryItemIndex) != mIsEquipped) { updateDisplay = true; } //We have it, and it's on cd if (mInventoryItem != null && Globals.Me.ItemOnCd(mInventoryItemIndex)) { updateDisplay = true; } //We have it, and it's on cd, and the fade is incorrect if (mInventoryItem != null && Globals.Me.ItemOnCd(mInventoryItemIndex) != mIsFaded) { updateDisplay = true; } } if (mCurrentSpell != null) //When it's a spell { //We don't know it, and the icon isn't faded! if (mSpellBookItem == null && !mIsFaded) { updateDisplay = true; } //Spell on cd if (mSpellBookItem != null && Globals.Me.GetSpellCooldown(mSpellBookItem.SpellId) > Globals.System.GetTimeMs()) { updateDisplay = true; } //Spell on cd and the fade is incorrect if (mSpellBookItem != null && Globals.Me.GetSpellCooldown(mSpellBookItem.SpellId) > Globals.System.GetTimeMs() != mIsFaded) { updateDisplay = true; } } if (updateDisplay) //Item on cd and fade is incorrect { if (mCurrentItem != null) { mCooldownLabel.IsHidden = true; mContentPanel.Show(); mContentPanel.Texture = Globals.ContentManager.GetTexture( GameContentManager.TextureType.Item, mCurrentItem.Icon ); if (mInventoryItemIndex > -1) { EquipPanel.IsHidden = !Globals.Me.IsEquipped(mInventoryItemIndex); EquipLabel.IsHidden = !Globals.Me.IsEquipped(mInventoryItemIndex); mIsFaded = Globals.Me.ItemOnCd(mInventoryItemIndex); if (mIsFaded) { mCooldownLabel.IsHidden = false; var secondsRemaining = (float)Globals.Me.ItemCdRemainder(mInventoryItemIndex) / 1000f; if (secondsRemaining > 10f) { mCooldownLabel.Text = Strings.Inventory.cooldown.ToString(secondsRemaining.ToString("N0")); } else { mCooldownLabel.Text = Strings.Inventory.cooldown.ToString( secondsRemaining.ToString("N1").Replace(".", Strings.Numbers.dec) ); } } mIsEquipped = Globals.Me.IsEquipped(mInventoryItemIndex); } else { EquipPanel.IsHidden = true; EquipLabel.IsHidden = true; mIsEquipped = false; mIsFaded = true; } mTexLoaded = true; } else if (mCurrentSpell != null) { mContentPanel.Show(); mContentPanel.Texture = Globals.ContentManager.GetTexture( GameContentManager.TextureType.Spell, mCurrentSpell.Icon ); EquipPanel.IsHidden = true; EquipLabel.IsHidden = true; mCooldownLabel.IsHidden = true; if (mSpellBookItem != null) { mIsFaded = Globals.Me.GetSpellCooldown(mSpellBookItem.SpellId) > Globals.System.GetTimeMs(); if (mIsFaded) { mCooldownLabel.IsHidden = false; var secondsRemaining = (float)(Globals.Me.GetSpellCooldown(mSpellBookItem.SpellId) - Globals.System.GetTimeMs()) / 1000f; if (secondsRemaining > 10f) { mCooldownLabel.Text = Strings.Spells.cooldown.ToString(secondsRemaining.ToString("N0")); } else { mCooldownLabel.Text = Strings.Spells.cooldown.ToString( secondsRemaining.ToString("N1").Replace(".", Strings.Numbers.dec) ); } } } else { mIsFaded = true; } mTexLoaded = true; mIsEquipped = false; } else { mContentPanel.Hide(); mTexLoaded = true; mIsEquipped = false; EquipPanel.IsHidden = true; EquipLabel.IsHidden = true; mCooldownLabel.IsHidden = true; } if (mIsFaded) { mContentPanel.RenderColor = new Color(100, 255, 255, 255); } else { mContentPanel.RenderColor = Color.White; } } if (mCurrentItem != null || mCurrentSpell != null) { if (!IsDragging) { if (mMouseOver) { if (!Globals.InputManager.MouseButtonDown(GameInput.MouseButtons.Left)) { mCanDrag = true; mMouseX = -1; mMouseY = -1; if (Globals.System.GetTimeMs() < mClickTime) { Activate(); mClickTime = 0; } } else { if (mCanDrag && Draggable.Active == null) { if (mMouseX == -1 || mMouseY == -1) { mMouseX = InputHandler.MousePosition.X - Pnl.LocalPosToCanvas(new Point(0, 0)).X; mMouseY = InputHandler.MousePosition.Y - Pnl.LocalPosToCanvas(new Point(0, 0)).Y; } else { var xdiff = mMouseX - (InputHandler.MousePosition.X - Pnl.LocalPosToCanvas(new Point(0, 0)).X); var ydiff = mMouseY - (InputHandler.MousePosition.Y - Pnl.LocalPosToCanvas(new Point(0, 0)).Y); if (Math.Sqrt(Math.Pow(xdiff, 2) + Math.Pow(ydiff, 2)) > 5) { IsDragging = true; mDragIcon = new Draggable( Pnl.LocalPosToCanvas(new Point(0, 0)).X + mMouseX, Pnl.LocalPosToCanvas(new Point(0, 0)).X + mMouseY, mContentPanel.Texture ); //SOMETHING SHOULD BE RENDERED HERE, RIGHT? } } } } } } else { if (mDragIcon.Update()) { mContentPanel.IsHidden = false; //Drug the item and now we stopped IsDragging = false; var dragRect = new FloatRect( mDragIcon.X - sItemXPadding / 2, mDragIcon.Y - sItemYPadding / 2, sItemXPadding / 2 + 32, sItemYPadding / 2 + 32 ); float bestIntersect = 0; var bestIntersectIndex = -1; if (Interface.GameUi.Hotbar.RenderBounds().IntersectsWith(dragRect)) { for (var i = 0; i < Options.MaxHotbar; i++) { if (Interface.GameUi.Hotbar.Items[i].RenderBounds().IntersectsWith(dragRect)) { if (FloatRect.Intersect(Interface.GameUi.Hotbar.Items[i].RenderBounds(), dragRect) .Width * FloatRect.Intersect(Interface.GameUi.Hotbar.Items[i].RenderBounds(), dragRect) .Height > bestIntersect) { bestIntersect = FloatRect.Intersect( Interface.GameUi.Hotbar.Items[i].RenderBounds(), dragRect ) .Width * FloatRect.Intersect( Interface.GameUi.Hotbar.Items[i].RenderBounds(), dragRect ) .Height; bestIntersectIndex = i; } } } if (bestIntersectIndex > -1 && bestIntersectIndex != mYindex) { Globals.Me.HotbarSwap(mYindex, (byte)bestIntersectIndex); } } mDragIcon.Dispose(); } else { mContentPanel.IsHidden = true; } } } }
private void LoadCraftItems(Guid id) { //Combined item mCraftId = id; if (mCombinedItem != null) { mCraftWindow.Children.Remove(mCombinedItem.Container); } //Clear the old item description box if (mCombinedItem != null && mCombinedItem.DescWindow != null) { mCombinedItem.DescWindow.Dispose(); } if (!Globals.ActiveCraftingTable.Crafts.Contains(id)) { return; } var craft = Globals.ActiveCraftingTable.Crafts.Get(id); if (craft == null) { return; } mCombinedItem = new RecipeItem(this, new CraftIngredient(craft.ItemId, 0)) { Container = new ImagePanel(mCraftWindow, "CraftedItem") }; mCombinedItem.Setup("CraftedItemIcon"); mCombinedValue = new Label(mCombinedItem.Container, "CraftedItemQuantity"); mCombinedItem.Container.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString()); mCombinedItem.LoadItem(); mCombinedValue.Show(); var quantity = Math.Max(craft.Quantity, 1); var itm = ItemBase.Get(craft.ItemId); if (itm == null || !itm.IsStackable) { quantity = 1; } mCombinedValue.Text = quantity.ToString(); for (var i = 0; i < mItems.Count; i++) { //Clear the old item description box if (mItems[i].DescWindow != null) { mItems[i].DescWindow.Dispose(); } mItemContainer.RemoveChild(mItems[i].Container, true); } mItems.Clear(); mValues.Clear(); //Quickly Look through the inventory and create a catalog of what items we have, and how many var itemdict = new Dictionary <Guid, int>(); foreach (var item in Globals.Me.Inventory) { if (item != null) { if (itemdict.ContainsKey(item.ItemId)) { itemdict[item.ItemId] += item.Quantity; } else { itemdict.Add(item.ItemId, item.Quantity); } } } for (var i = 0; i < craft.Ingredients.Count; i++) { mItems.Add(new RecipeItem(this, craft.Ingredients[i])); mItems[i].Container = new ImagePanel(mItemContainer, "CraftingIngredient"); mItems[i].Setup("IngredientItemIcon"); var lblTemp = new Label(mItems[i].Container, "IngredientItemValue"); var onHand = 0; if (itemdict.ContainsKey(craft.Ingredients[i].ItemId)) { onHand = itemdict[craft.Ingredients[i].ItemId]; } lblTemp.Text = onHand + "/" + craft.Ingredients[i].Quantity; mValues.Add(lblTemp); mItems[i].Container.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString()); mItems[i].LoadItem(); var xPadding = mItems[i].Container.Margin.Left + mItems[i].Container.Margin.Right; var yPadding = mItems[i].Container.Margin.Top + mItems[i].Container.Margin.Bottom; mItems[i] .Container.SetPosition( i % ((mItemContainer.Width - mItemContainer.GetVerticalScrollBar().Width) / (mItems[i].Container.Width + xPadding)) * (mItems[i].Container.Width + xPadding) + xPadding, i / ((mItemContainer.Width - mItemContainer.GetVerticalScrollBar().Width) / (mItems[i].Container.Width + xPadding)) * (mItems[i].Container.Height + yPadding) + yPadding ); } //If crafting & we no longer have the items for the craft then stop! if (Crafting) { var cancraft = true; foreach (var c in CraftBase.Get(mCraftId).Ingredients) { if (itemdict.ContainsKey(c.ItemId)) { if (itemdict[c.ItemId] >= c.Quantity) { itemdict[c.ItemId] -= c.Quantity; } else { cancraft = false; break; } } else { cancraft = false; break; } } if (!cancraft) { Crafting = false; mCraftWindow.IsClosable = true; mBar.Width = 0; ChatboxMsg.AddMessage(new ChatboxMsg(Strings.Crafting.incorrectresources, Color.Red)); return; } } }
private void AssignEditorItem(Guid id) { mEditorItem = ItemBase.Get(id); UpdateEditor(); }
private void UpdateImage() { var faceTex = Globals.ContentManager.GetTexture(GameContentManager.TextureType.Face, MyEntity.Face); var entityTex = MyEntity.Texture; if (faceTex != null && faceTex != EntityFace.Texture) { EntityFace.Texture = faceTex; EntityFace.RenderColor = MyEntity.Color ?? new Color(255, 255, 255, 255); EntityFace.SetTextureRect(0, 0, faceTex.GetWidth(), faceTex.GetHeight()); EntityFace.SizeToContents(); Align.Center(EntityFace); mCurrentSprite = MyEntity.Face; EntityFace.IsHidden = false; var i = 0; for (var z = 0; z < Options.PaperdollOrder[1].Count; z++) { if (Options.PaperdollOrder[1][z] != "Player") { if (PaperdollPanels == null) { Log.Warn($@"{nameof(PaperdollPanels)} is null."); } else if (PaperdollPanels[i] == null) { Log.Warn($@"{nameof(PaperdollPanels)}[{i}] is null."); } PaperdollPanels?[i]?.Hide(); i++; } } } else if (entityTex != null && faceTex == null || faceTex != null && faceTex != EntityFace.Texture) { if (entityTex != EntityFace.Texture) { EntityFace.Texture = entityTex; EntityFace.RenderColor = MyEntity.Color ?? new Color(255, 255, 255, 255); EntityFace.SetTextureRect(0, 0, entityTex.GetWidth() / Options.Instance.Sprites.NormalFrames, entityTex.GetHeight() / Options.Instance.Sprites.Directions); EntityFace.SizeToContents(); Align.Center(EntityFace); mCurrentSprite = MyEntity.MySprite; EntityFace.IsHidden = false; } var equipment = MyEntity.Equipment; if (MyEntity == Globals.Me) { for (var i = 0; i < MyEntity.MyEquipment.Length; i++) { var eqp = MyEntity.MyEquipment[i]; if (eqp > -1 && eqp < Options.MaxInvItems) { equipment[i] = MyEntity.Inventory[eqp].ItemId; } else { equipment[i] = Guid.Empty; } } } var n = 0; for (var z = 0; z < Options.PaperdollOrder[1].Count; z++) { var paperdoll = ""; if (Options.EquipmentSlots.IndexOf(Options.PaperdollOrder[1][z]) > -1 && equipment.Length == Options.EquipmentSlots.Count) { if (equipment[Options.EquipmentSlots.IndexOf(Options.PaperdollOrder[1][z])] != Guid.Empty) { var itemId = equipment[Options.EquipmentSlots.IndexOf(Options.PaperdollOrder[1][z])]; if (ItemBase.Get(itemId) != null) { var itemdata = ItemBase.Get(itemId); if (MyEntity.Gender == 0) { paperdoll = itemdata.MalePaperdoll; } else { paperdoll = itemdata.FemalePaperdoll; } } } } //Check for Player layer if (Options.PaperdollOrder[1][z] == "Player") { continue; } if (paperdoll == "" && PaperdollTextures[n] != "") { PaperdollPanels[n].Texture = null; PaperdollPanels[n].Hide(); PaperdollTextures[n] = ""; } else if (paperdoll != "" && paperdoll != PaperdollTextures[n]) { var paperdollTex = Globals.ContentManager.GetTexture( GameContentManager.TextureType.Paperdoll, paperdoll ); PaperdollPanels[n].Texture = paperdollTex; if (paperdollTex != null) { PaperdollPanels[n] .SetTextureRect( 0, 0, PaperdollPanels[n].Texture.GetWidth() / Options.Instance.Sprites.NormalFrames, PaperdollPanels[n].Texture.GetHeight() / Options.Instance.Sprites.Directions ); PaperdollPanels[n] .SetSize( PaperdollPanels[n].Texture.GetWidth() / Options.Instance.Sprites.NormalFrames, PaperdollPanels[n].Texture.GetHeight() / Options.Instance.Sprites.Directions ); PaperdollPanels[n] .SetPosition( EntityFaceContainer.Width / 2 - PaperdollPanels[n].Width / 2, EntityFaceContainer.Height / 2 - PaperdollPanels[n].Height / 2 ); } PaperdollPanels[n].Show(); PaperdollTextures[n] = paperdoll; } //Check for Player layer if (Options.PaperdollOrder[1][z] != "Player") { n++; } } } else if (MyEntity.MySprite != mCurrentSprite && MyEntity.Face != mCurrentSprite) { EntityFace.IsHidden = true; for (var i = 0; i < Options.EquipmentSlots.Count; i++) { PaperdollPanels[i]?.Hide(); } } if (EntityFace.RenderColor != MyEntity.Color) { EntityFace.RenderColor = MyEntity.Color; } }
public void Update() { var equipped = false; for (var i = 0; i < Options.EquipmentSlots.Count; i++) { if (Globals.Me.MyEquipment[i] == mMySlot) { equipped = true; break; } } var item = ItemBase.Get(Globals.Me.Inventory[mMySlot].ItemId); if (Globals.Me.Inventory[mMySlot].ItemId != mCurrentItemId || Globals.Me.Inventory[mMySlot].Quantity != mCurrentAmt || equipped != mIsEquipped || item == null && mTexLoaded != "" || item != null && mTexLoaded != item.Icon || mIconCd != Globals.Me.ItemOnCd(mMySlot) || Globals.Me.ItemOnCd(mMySlot)) { mCurrentItemId = Globals.Me.Inventory[mMySlot].ItemId; mCurrentAmt = Globals.Me.Inventory[mMySlot].Quantity; mIsEquipped = equipped; EquipPanel.IsHidden = !mIsEquipped; EquipLabel.IsHidden = !mIsEquipped; mCooldownLabel.IsHidden = true; if (item != null) { var itemTex = Globals.ContentManager.GetTexture(GameContentManager.TextureType.Item, item.Icon); if (itemTex != null) { Pnl.Texture = itemTex; if (Globals.Me.ItemOnCd(mMySlot)) { Pnl.RenderColor = new Color(100, item.Color.R, item.Color.G, item.Color.B); } else { Pnl.RenderColor = item.Color; } } else { if (Pnl.Texture != null) { Pnl.Texture = null; } } mTexLoaded = item.Icon; mIconCd = Globals.Me.ItemOnCd(mMySlot); if (mIconCd) { mCooldownLabel.IsHidden = false; var secondsRemaining = (float)Globals.Me.ItemCdRemainder(mMySlot) / 1000f; if (secondsRemaining > 10f) { mCooldownLabel.Text = Strings.Inventory.cooldown.ToString(secondsRemaining.ToString("N0")); } else { mCooldownLabel.Text = Strings.Inventory.cooldown.ToString( secondsRemaining.ToString("N1").Replace(".", Strings.Numbers.dec) ); } } } else { if (Pnl.Texture != null) { Pnl.Texture = null; } mTexLoaded = ""; } if (mDescWindow != null) { mDescWindow.Dispose(); mDescWindow = null; pnl_HoverEnter(null, null); } } if (!IsDragging) { if (mMouseOver) { if (!Globals.InputManager.MouseButtonDown(GameInput.MouseButtons.Left)) { mCanDrag = true; mMouseX = -1; mMouseY = -1; if (Globals.System.GetTimeMs() < mClickTime) { Globals.Me.TryUseItem(mMySlot); mClickTime = 0; } } else { if (mCanDrag && Draggable.Active == null) { if (mMouseX == -1 || mMouseY == -1) { mMouseX = InputHandler.MousePosition.X - Pnl.LocalPosToCanvas(new Point(0, 0)).X; mMouseY = InputHandler.MousePosition.Y - Pnl.LocalPosToCanvas(new Point(0, 0)).Y; } else { var xdiff = mMouseX - (InputHandler.MousePosition.X - Pnl.LocalPosToCanvas(new Point(0, 0)).X); var ydiff = mMouseY - (InputHandler.MousePosition.Y - Pnl.LocalPosToCanvas(new Point(0, 0)).Y); if (Math.Sqrt(Math.Pow(xdiff, 2) + Math.Pow(ydiff, 2)) > 5) { IsDragging = true; mDragIcon = new Draggable( Pnl.LocalPosToCanvas(new Point(0, 0)).X + mMouseX, Pnl.LocalPosToCanvas(new Point(0, 0)).X + mMouseY, Pnl.Texture ); } } } } } } else { if (mDragIcon.Update()) { //Drug the item and now we stopped IsDragging = false; var dragRect = new FloatRect( mDragIcon.X - (Container.Padding.Left + Container.Padding.Right) / 2, mDragIcon.Y - (Container.Padding.Top + Container.Padding.Bottom) / 2, (Container.Padding.Left + Container.Padding.Right) / 2 + Pnl.Width, (Container.Padding.Top + Container.Padding.Bottom) / 2 + Pnl.Height ); float bestIntersect = 0; var bestIntersectIndex = -1; //So we picked up an item and then dropped it. Lets see where we dropped it to. //Check inventory first. if (mInventoryWindow.RenderBounds().IntersectsWith(dragRect)) { for (var i = 0; i < Options.MaxInvItems; i++) { if (mInventoryWindow.Items[i].RenderBounds().IntersectsWith(dragRect)) { if (FloatRect.Intersect(mInventoryWindow.Items[i].RenderBounds(), dragRect).Width * FloatRect.Intersect(mInventoryWindow.Items[i].RenderBounds(), dragRect).Height > bestIntersect) { bestIntersect = FloatRect.Intersect(mInventoryWindow.Items[i].RenderBounds(), dragRect).Width * FloatRect.Intersect(mInventoryWindow.Items[i].RenderBounds(), dragRect).Height; bestIntersectIndex = i; } } } if (bestIntersectIndex > -1) { if (mMySlot != bestIntersectIndex) { //Try to swap.... PacketSender.SendSwapInvItems(bestIntersectIndex, mMySlot); Globals.Me.SwapItems(bestIntersectIndex, mMySlot); } } } else if (Interface.GameUi.Hotbar.RenderBounds().IntersectsWith(dragRect)) { for (var i = 0; i < Options.MaxHotbar; i++) { if (Interface.GameUi.Hotbar.Items[i].RenderBounds().IntersectsWith(dragRect)) { if (FloatRect.Intersect( Interface.GameUi.Hotbar.Items[i].RenderBounds(), dragRect ) .Width * FloatRect.Intersect(Interface.GameUi.Hotbar.Items[i].RenderBounds(), dragRect) .Height > bestIntersect) { bestIntersect = FloatRect.Intersect(Interface.GameUi.Hotbar.Items[i].RenderBounds(), dragRect) .Width * FloatRect.Intersect(Interface.GameUi.Hotbar.Items[i].RenderBounds(), dragRect) .Height; bestIntersectIndex = i; } } } if (bestIntersectIndex > -1) { Globals.Me.AddToHotbar((byte)bestIntersectIndex, 0, mMySlot); } } else if (Globals.InBag) { var bagWindow = Interface.GameUi.GetBag(); if (bagWindow.RenderBounds().IntersectsWith(dragRect)) { for (var i = 0; i < Globals.Bag.Length; i++) { if (bagWindow.Items[i].RenderBounds().IntersectsWith(dragRect)) { if (FloatRect.Intersect(bagWindow.Items[i].RenderBounds(), dragRect).Width * FloatRect.Intersect(bagWindow.Items[i].RenderBounds(), dragRect).Height > bestIntersect) { bestIntersect = FloatRect.Intersect(bagWindow.Items[i].RenderBounds(), dragRect).Width * FloatRect.Intersect(bagWindow.Items[i].RenderBounds(), dragRect).Height; bestIntersectIndex = i; } } } if (bestIntersectIndex > -1) { Globals.Me.TryStoreBagItem(mMySlot, bestIntersectIndex); } } } //We may need to check if its a ground tile we just dropped on at some point. else { var xModifier = 0; var yModifier = 0; switch (Globals.Me.Dir) { case 0: yModifier--; break; case 1: yModifier++; break; case 2: xModifier--; break; case 3: xModifier++; break; } PacketSender.SendDropItem(mMySlot, 1, Globals.Me.MapInstance.Id, Globals.Me.X + xModifier, Globals.Me.Y + yModifier); } mDragIcon.Dispose(); } } }
void pnl_HoverEnter(Base sender, EventArgs arguments) { if (InputHandler.MouseFocus != null) { return; } mMouseOver = true; mCanDrag = true; if (Globals.InputManager.MouseButtonDown(GameInput.MouseButtons.Left)) { mCanDrag = false; return; } if (mDescWindow != null) { mDescWindow.Dispose(); mDescWindow = null; } if (Globals.GameShop == null) { if (Globals.Me.Inventory[mMySlot]?.Base != null) { mDescWindow = new ItemDescWindow( Globals.Me.Inventory[mMySlot].Base, Globals.Me.Inventory[mMySlot].Quantity, mInventoryWindow.X, mInventoryWindow.Y, Globals.Me.Inventory[mMySlot].StatBuffs ); } } else { var invItem = Globals.Me.Inventory[mMySlot]; ShopItem shopItem = null; for (var i = 0; i < Globals.GameShop.BuyingItems.Count; i++) { var tmpShop = Globals.GameShop.BuyingItems[i]; if (invItem.ItemId == tmpShop.ItemId) { shopItem = tmpShop; break; } } if (Globals.GameShop.BuyingWhitelist && shopItem != null) { var hoveredItem = ItemBase.Get(shopItem.CostItemId); if (hoveredItem != null && Globals.Me.Inventory[mMySlot]?.Base != null) { mDescWindow = new ItemDescWindow( Globals.Me.Inventory[mMySlot].Base, Globals.Me.Inventory[mMySlot].Quantity, mInventoryWindow.X, mInventoryWindow.Y, Globals.Me.Inventory[mMySlot].StatBuffs, "", Strings.Shop.sellsfor.ToString(shopItem.CostItemQuantity, hoveredItem.Name) ); } } else if (shopItem == null) { var costItem = Globals.GameShop.DefaultCurrency; if (invItem.Base != null && costItem != null && Globals.Me.Inventory[mMySlot]?.Base != null) { mDescWindow = new ItemDescWindow( Globals.Me.Inventory[mMySlot].Base, Globals.Me.Inventory[mMySlot].Quantity, mInventoryWindow.X, mInventoryWindow.Y, Globals.Me.Inventory[mMySlot].StatBuffs, "", Strings.Shop.sellsfor.ToString(invItem.Base.Price.ToString(), costItem.Name) ); } } else { if (invItem?.Base != null) { mDescWindow = new ItemDescWindow( invItem.Base, invItem.Quantity, mInventoryWindow.X, mInventoryWindow.Y, invItem.StatBuffs, "", Strings.Shop.wontbuy ); } } } }
public ItemBase GetItem() { return(ItemBase.Get(ItemId)); }
private void cmbItem_SelectedIndexChanged(object sender, EventArgs e) { mEditorItem.Ammo = ItemBase.Get(ItemBase.IdFromList(cmbItem.SelectedIndex - 1)); }
public void Generate(Map map) { this.map = map; map.Entities.Clear(); map.Spawns.Clear(); map.IsAutospawn = true; map.Music = "Overworld"; map.SeaLevel = map.Height / 5; Utility.StatusMessage = "Let there be space."; map.Materials = new byte[map.Width * map.Height]; Utility.StatusMessage = "Let there be air."; map.Fill(Material.Air, new Rectangle(0, 0, map.Width, map.SeaLevel)); Utility.StatusMessage = "Let there be dirt."; var dirtLevel = map.SeaLevel; var clayHeight = dirtLevel + 200; var sandstoneHeight = map.GetTierAltitude(2) / Map.BlockHeight; var sectionHeight = (map.Height - sandstoneHeight) / 7; var limestoneHeight = map.GetTierAltitude(3) / Map.BlockHeight; var quartziteHeight = map.GetTierAltitude(4) / Map.BlockHeight; var graniteHeight = map.GetTierAltitude(5) / Map.BlockHeight; var marbleHeight = map.GetTierAltitude(6) / Map.BlockHeight; var rhyoliteHeight = map.GetTierAltitude(7) / Map.BlockHeight; var basaltHeight = map.GetTierAltitude(8) / Map.BlockHeight; map.Fill(Material.Dirt, new Rectangle(0, dirtLevel, map.Width, 200)); Utility.StatusMessage = "Let there be clay."; map.Fill(Material.Clay, new Rectangle(0, clayHeight, map.Width, 300)); Utility.StatusMessage = "Let there be sandstone."; map.Fill(Material.Sandstone, new Rectangle(0, sandstoneHeight, map.Width, sectionHeight)); Utility.StatusMessage = "Let there be limestone."; map.Fill(Material.Limestone, new Rectangle(0, limestoneHeight, map.Width, sectionHeight)); Utility.StatusMessage = "Let there be granite."; map.Fill(Material.Quartzite, new Rectangle(0, quartziteHeight, map.Width, sectionHeight)); Utility.StatusMessage = "Let there be quartzite."; map.Fill(Material.Granite, new Rectangle(0, graniteHeight, map.Width, sectionHeight)); Utility.StatusMessage = "Let there be marble."; map.Fill(Material.Marble, new Rectangle(0, marbleHeight, map.Width, sectionHeight)); Utility.StatusMessage = "Let there be rhyolite."; map.Fill(Material.Rhyolite, new Rectangle(0, rhyoliteHeight, map.Width, sectionHeight)); Utility.StatusMessage = "Let there be basalt."; map.Fill(Material.Basalt, new Rectangle(0, basaltHeight, map.Width, sectionHeight)); Utility.StatusMessage = "Let there be rough terrain."; map.CreateHills(Material.Clay, Material.Dirt, clayHeight, 3 * VerticalScale); map.CreateHills(Material.Sandstone, Material.Clay, sandstoneHeight, 3 * VerticalScale); map.CreateHills(Material.Limestone, Material.Sandstone, limestoneHeight, 6 * VerticalScale); map.CreateHills(Material.Quartzite, Material.Limestone, quartziteHeight, 6 * VerticalScale); map.CreateHills(Material.Granite, Material.Quartzite, graniteHeight, 6 * VerticalScale); map.CreateHills(Material.Marble, Material.Granite, marbleHeight, 6 * VerticalScale); map.CreateHills(Material.Rhyolite, Material.Marble, rhyoliteHeight, 3 * VerticalScale); Utility.StatusMessage = "Let there be hills and lakes."; map.CreateHills(Material.Dirt, Material.Water, dirtLevel, 200, -200, 200, -200); map.SprinkleVeins(Material.Clay, dirtLevel - 500, clayHeight, 10000, 50, Brush.Size7); map.SprinkleVeins(Material.Sandstone, clayHeight, sandstoneHeight, 10000, 50, Brush.Size7); map.SprinkleVeins(Material.Limestone, sandstoneHeight, limestoneHeight, 10000, 50, Brush.Size7); map.SprinkleVeins(Material.Quartzite, limestoneHeight, quartziteHeight, 10000, 50, Brush.Size7); map.SprinkleVeins(Material.Granite, quartziteHeight, graniteHeight, 10000, 50, Brush.Size7); map.SprinkleVeins(Material.Marble, graniteHeight, marbleHeight, 10000, 50, Brush.Size7); map.SprinkleVeins(Material.Rhyolite, marbleHeight, rhyoliteHeight, 10000, 50, Brush.Size7); map.SprinkleVeins(Material.Basalt, rhyoliteHeight, basaltHeight, 10000, 50, Brush.Size7); map.SprinkleVeins(Material.Lava, basaltHeight, map.Height, 10000, 50, Brush.Size7); Utility.StatusMessage = "Let there be lava."; var topLavaHeight = basaltHeight - 5 * VerticalScale; map.LavaLevel = topLavaHeight; map.Fill(Material.Lava, new Rectangle(0, topLavaHeight, map.Width, 5 * VerticalScale)); var bottomLavaHeight = map.Height - 5 * VerticalScale; map.Fill(Material.Lava, new Rectangle(0, bottomLavaHeight, map.Width, 5 * VerticalScale)); map.CreateHills(Material.Lava, Material.Rhyolite, topLavaHeight, 4 * VerticalScale); map.CreateHills(Material.Basalt, Material.Lava, basaltHeight, 4 * VerticalScale); map.CreateHills(Material.Lava, Material.Basalt, bottomLavaHeight, 6 * VerticalScale); map.SprinkleVeins(Material.Water, clayHeight, rhyoliteHeight, 250000, 100, Brush.Size9); map.SprinkleVeins(Material.Gravel, map.SeaLevel + 100, rhyoliteHeight, 250000, 50, Brush.Size9); map.SprinkleVeins(Material.Lava, marbleHeight, map.Height, 150000, 100, Brush.Size9); map.SprinkleVeins(Material.PoisonGas, marbleHeight, map.Height, 150000, 300, Brush.Size9); map.SprinkleVeins(Material.Oil, marbleHeight, map.Height, 150000, 150, Brush.Size9); Utility.StatusMessage = "Let there be floating islands."; map.SprinkleVeins(Material.Dirt, 100, sectionHeight, 125000, 350, Brush.Size10, (position) => { if (!Utility.Roll8()) { AddRandomSpawns(position, true); } if (Utility.Roll4()) { var chestPosition = map.FindGround(new Vector2(position.X, 0)) + new Vector2(0, -50); var chest = map.AddPlaceable(null, ItemBase.Get(ItemId.WorldHypercube), chestPosition); var tier = 3; chest.AddItem(GenerateRandomItem(tier)); chest.AddItem(GenerateRandomItem(tier)); chest.AddItem(GenerateRandomItem(tier)); chest.AddItem(GenerateRandomItem(tier)); chest.AddItem(GenerateRandomItem(tier)); } }, false ); Utility.StatusMessage = "Let there be caves."; map.SprinkleVeins(Material.Air, map.SeaLevel - 300, map.Height, 50000, 450, Brush.Size9, (position) => { if (Utility.Flip()) { map.AddPlaceable(null, ItemBase.Get(ItemId.LightOrb), position); } if (!Utility.Roll8()) { AddRandomSpawns(position); } if (Utility.Roll4()) { var chest = map.AddPlaceable(null, ItemBase.Get(ItemId.WorldHypercube), position); var tier = map.GetTier(position); chest.AddItem(GenerateRandomItem(tier)); chest.AddItem(GenerateRandomItem(tier)); chest.AddItem(GenerateRandomItem(tier)); chest.AddItem(GenerateRandomItem(tier)); chest.AddItem(GenerateRandomItem(tier)); } } ); map.StartingPosition = new Vector2(map.PixelWidth / 2, (sectionHeight * Map.BlockHeight) + 1200); // add 1200 here so that spawn won't catch an island right in the center as it descends down. map.StartingPosition = map.FindGround(map.StartingPosition); map.StartingPosition = new Vector2(map.StartingPosition.X, map.StartingPosition.Y - 200f); AddPortal(map.StartingPosition, Material.Bone).Remove(); var portal = AddPortal(new Vector2(map.StartingPosition.X, map.SeaLevelInPixels), Material.Bone); portal.Name = "Dungeon Tier 2"; portal.Value = "KrawnixLair"; map.AddEntity(new Placeable() { TypeId = ItemId.Workbench, Position = portal.Position + new Vector2(-80, 50) }); portal = AddPortal(new Vector2(Utility.Next(1000, map.PixelWidth - 1000), map.GetTierAltitude(3) - Utility.Next(300, sectionHeight * Map.BlockHeight - 300)), Material.Bone); portal.Name = "Dungeon Tier 3"; portal.Value = "Botanica"; var skyPortalIslandPosition = new Vector2(Utility.Next(1000, map.PixelWidth - 1000), Utility.Next(500, sectionHeight * Map.BlockHeight - 100)); map.CreateVein(Material.Dirt, skyPortalIslandPosition, 350, Brush.Size10, false); skyPortalIslandPosition = map.FindGround(skyPortalIslandPosition); portal = AddPortal(skyPortalIslandPosition + new Vector2(0, -50), Material.Bone); portal.Name = "Dungeon Tier 4"; portal.Value = "SkyRealm"; portal = AddPortal(new Vector2(Utility.Next(1000, map.PixelWidth - 1000), map.GetTierAltitude(5) - Utility.Next(300, sectionHeight * Map.BlockHeight - 300)), Material.Bone); portal.Name = "Dungeon Tier 5"; portal.Value = "Oberon"; portal = AddPortal(new Vector2(Utility.Next(1000, map.PixelWidth - 1000), map.GetTierAltitude(6) - Utility.Next(300, sectionHeight * Map.BlockHeight - 300)), Material.Bone); portal.Name = "Dungeon Tier 6"; portal.Value = "Water"; portal = AddPortal(new Vector2(Utility.Next(1000, map.PixelWidth - 1000), map.GetTierAltitude(7) - Utility.Next(300, sectionHeight * Map.BlockHeight - 300)), Material.Bone); portal.Name = "Dungeon Tier 7"; portal.Value = "Portal"; portal = AddPortal(new Vector2(Utility.Next(1000, map.PixelWidth - 1000), map.GetTierAltitude(8) - Utility.Next(300, sectionHeight * Map.BlockHeight - 300)), Material.Bone); portal.Name = "Dungeon Tier 8"; portal.Value = "Vesuvius"; portal = AddPortal(new Vector2(Utility.Next(1000, map.PixelWidth - 1000), map.GetTierAltitude(8) + Utility.Next(300, sectionHeight * Map.BlockHeight - 300)), Material.Bone); portal.Name = "Dungeon Tier 9"; portal.Value = "FinalBoss"; Utility.StatusMessage = "Let there be grass, snow and thin strips of terrain to hold up the oceans."; for (var y = 0; y < map.Height; y++) { var levelMaterial = Material.Dirt; if (y > clayHeight) { levelMaterial = Material.Clay; } if (y > sandstoneHeight) { levelMaterial = Material.Sandstone; } if (y > limestoneHeight) { levelMaterial = Material.Limestone; } if (y > quartziteHeight) { levelMaterial = Material.Quartzite; } if (y > graniteHeight) { levelMaterial = Material.Granite; } if (y > marbleHeight) { levelMaterial = Material.Marble; } if (y > rhyoliteHeight) { levelMaterial = Material.Rhyolite; } if (y > map.LavaLevel + 25) { levelMaterial = Material.Basalt; } for (var x = 0; x < map.Width; x++) { var material = map.GetMaterial(x, y); if (MaterialInfo.IsLiquid(material)) { if (MaterialInfo.IsGas(map.GetMaterial(x, y + 1))) { map.SetMaterial(x, y + 1, levelMaterial); } if (MaterialInfo.IsGas(map.GetMaterial(x - 1, y))) { map.SetMaterial(x - 1, y, levelMaterial); } if (MaterialInfo.IsGas(map.GetMaterial(x + 1, y))) { map.SetMaterial(x + 1, y, levelMaterial); } } else { // this is my horrible attempt at erosion. //var adjacent = IsAdjacent(x, y, Material.Air); //if (adjacent != Direction.Up && adjacent != Direction.Left && adjacent != Direction.None) //{ // SetMaterial(x, y, Material.Air); // continue; //} switch (material) { case Material.Dirt: if (map.GetMaterial(x, y - 1) == Material.Air) { if (y < map.SeaLevel + 15) { map.SetMaterial(x, y, Material.Grass); if (y < map.SeaLevel - 50) { map.SetMaterial(x, y - 1, Material.Snow); if (Utility.Flip()) { map.SetMaterial(x, y - 2, Material.Snow); } } } } //else //{ // if (GetMaterial(x, y - 1) == Material.Water) // SetMaterial(x, y, Material.Mud); //} break; } } } } Utility.StatusMessage = "Let there be sandy beaches."; const int beachWidth = 600; const int beachHeight = 10; for (int i = 0; i < beachWidth; i++) { var ground = map.FindGround(new Vector2(i * Map.BlockWidth, map.SeaLevelInPixels - sectionHeight / 2 * Map.BlockHeight)); for (int y = 0; y < beachHeight; y++) { map.SetMaterialAtPixel(ground + new Vector2(0, -Map.BlockHeight * y), Material.Sand); } } for (int i = map.Width - 420; i < map.Width; i++) { var ground = map.FindGround(new Vector2(i * Map.BlockWidth, map.SeaLevelInPixels - sectionHeight / 2 * Map.BlockHeight)); for (int y = 0; y < beachHeight; y++) { map.SetMaterialAtPixel(ground + new Vector2(0, -Map.BlockHeight * y), Material.Sand); } } map.WallMaterials = (byte[])map.Materials.Clone(); for (int i = 0; i < map.WallMaterials.Length; i++) { if (map.WallMaterials[i] == (byte)Material.Water) { map.WallMaterials[i] = (byte)Material.Dirt; } } Utility.StatusMessage = "Let there be coal."; map.SprinkleVeins(Material.Coal, map.SeaLevel - 300, map.Height, 50000, 50, Brush.Size4); Utility.StatusMessage = "Let there be iron."; map.SprinkleVeins(Material.IronOre, map.SeaLevel - 300, map.SeaLevel + sectionHeight * 5, 10000, 100); Utility.StatusMessage = "Let there be aluminum."; map.SprinkleVeins(Material.AluminumOre, sandstoneHeight, sandstoneHeight + sectionHeight * 5, 15000, 100); Utility.StatusMessage = "Let there be copper."; map.SprinkleVeins(Material.CopperOre, sandstoneHeight, sandstoneHeight + sectionHeight * 2, 15000, 100); Utility.StatusMessage = "Let there be silver."; map.SprinkleVeins(Material.SilverOre, limestoneHeight, limestoneHeight + sectionHeight * 2, 15000, 100); Utility.StatusMessage = "Let there be gold."; map.SprinkleVeins(Material.GoldOre, quartziteHeight, graniteHeight + sectionHeight * 2, 15000, 100); Utility.StatusMessage = "Let there be dilithium."; map.SprinkleVeins(Material.Dilithium, graniteHeight, quartziteHeight + sectionHeight * 2, 15000, 40); Utility.StatusMessage = "Let there be radium."; map.SprinkleVeins(Material.RadiumOre, marbleHeight, marbleHeight + sectionHeight * 2, 15000, 40); Utility.StatusMessage = "Let there be uranium."; map.SprinkleVeins(Material.UraniumOre, basaltHeight, map.Height, 10000, 20); Utility.StatusMessage = "Let there be sodium."; map.SprinkleVeins(Material.Sodium, map.SeaLevel - 300, map.SeaLevel + sectionHeight * 4, 20000, 30); Utility.StatusMessage = "Let there be sulpher."; map.SprinkleVeins(Material.Sulfur, clayHeight, clayHeight + sectionHeight * 3, 25000, 20); Utility.StatusMessage = "Let there be topaz."; map.SprinkleVeins(Material.Topaz, sandstoneHeight, sandstoneHeight + sectionHeight, 25000, 20); Utility.StatusMessage = "Let there be amethyst."; map.SprinkleVeins(Material.Amethyst, limestoneHeight, limestoneHeight + sectionHeight, 25000, 20); Utility.StatusMessage = "Let there be emerald."; map.SprinkleVeins(Material.Emerald, quartziteHeight, quartziteHeight + sectionHeight, 25000, 20); Utility.StatusMessage = "Let there be sapphire."; map.SprinkleVeins(Material.Sapphire, graniteHeight, graniteHeight + sectionHeight, 25000, 20); Utility.StatusMessage = "Let there be rubies."; map.SprinkleVeins(Material.Ruby, marbleHeight, marbleHeight + sectionHeight, 25000, 20); Utility.StatusMessage = "Let there be diamonds."; map.SprinkleVeins(Material.Diamond, rhyoliteHeight, rhyoliteHeight + sectionHeight * 2, 25000, 20); foreach (var player in map.Players) { map.Entities.Add(player); player.Respawn(); } // so that entities actually get saved map.FlushEntities(); Utility.StatusMessage = ""; }