protected PaintData getPaintData() { if (_overridePaintData != null) { return(_overridePaintData); } PaintData data = new PaintData(paintCyclingTimeScale, -1, null, false, 0); if (npcOwner != -1) { NPC npc = getNPC(npcOwner); if (npc == null) { return(data); } WoMDNPC gNpc = npc.GetGlobalNPC <WoMDNPC>(); return(gNpc.paintData); } WoMDPlayer player = getModPlayer(projectile.owner); if (player == null) { return(data); } return(player.paintData); }
public override bool UseItem(Player player) { WoMDPlayer p = player.GetModPlayer <WoMDPlayer>(); if (p == null) { return(false); } soundTimer--; if (soundTimer <= 0) { Main.PlaySound(SoundID.Item, player.position); soundTimer = soundFrequency; } Point mousePosition = Main.MouseWorld.ToTileCoordinates(); Point playerPos = player.position.ToTileCoordinates(); int xOffset = mousePosition.X - playerPos.X; int yOffset = mousePosition.Y - playerPos.Y; if (yOffset < 0) { yOffset--; } if (isInRange(player, xOffset, yOffset)) { PaintData data = p.paintData.clone(); data.paintMethod = PaintMethods.BlocksAndWalls; paint(mousePosition.X, mousePosition.Y, data, true); } return(true); }
protected virtual Texture2D getTexture(WoMDPlayer player) { //default handling based on conventions with texture counts and texture names switch (textureCount) { case 2: //expects a default version with no paint, and a version with paint if ((player.paintData.PaintColor == -1 && player.paintData.CustomPaint == null) || player.paintData.paintMethod == PaintMethods.RemovePaint) { return(null); } return(getExtraTexture(GetType().Name + "Painted")); case 3: //expects a default version with no paint, and versions with paint and as a paint scraper if (player.paintData.paintMethod == PaintMethods.RemovePaint) { return(getExtraTexture(GetType().Name + "Scraper")); } if (player.paintData.PaintColor == -1 && player.paintData.CustomPaint == null) { return(null); } return(getExtraTexture(GetType().Name + "Painted")); } return(null); }
/// <summary> /// Gets a shader for the provided PaintingItem. Possible results are the GSPainted and PaintedNegative shaders. /// </summary> /// <param name="item"></param> /// <param name="player"></param> /// <returns></returns> public static MiscShaderData getShader(PaintingItem item, Player player) { if (player == null) { return(null); } if (item == null) { return(null); } WoMDPlayer modPlayer = player.GetModPlayer <WoMDPlayer>(); if (modPlayer == null) { return(null); } PaintData data = modPlayer.paintData.clone(); data.paintMethod = item.overridePaintMethod(modPlayer); if (data.paintMethod == PaintMethods.RemovePaint) { return(null); } if (data.PaintColor == PaintID.Negative || data.CustomPaint is NegativeSprayPaint) { return(getNegativeShader()); } return(getGSShader(data.RenderColor)); }
//This is where the painted buff is applied to NPCs that the item hits with melee public override void OnHitNPC(Player p, NPC target, int damage, float knockBack, bool crit) { WoMDNPC npc = target.GetGlobalNPC <WoMDNPC>(); if (npc != null && p != null && item.owner == Main.myPlayer) { WoMDPlayer player = p.GetModPlayer <WoMDPlayer>(); PaintMethods method = overridePaintMethod(player); if (method != PaintMethods.None) { if (method == PaintMethods.RemovePaint) { npc.painted = false; int index = target.FindBuffIndex(BuffType <Painted>()); if (index >= 0) { target.DelBuff(index); } } else { applyPaintedToNPC(target, new PaintData(npcCyclingTimeScale, player.paintData.PaintColor, player.paintData.CustomPaint, player.paintData.CustomPaint is ISprayPaint, Main.GlobalTime, player: player.player)); } } } }
//This is what fills in the "Current Tool" and "Current Paint" lines of the tooltip public override void ModifyTooltips(List <TooltipLine> tooltips) { Player p = getPlayer(item.owner); if (p == null) { return; } WoMDPlayer player = p.GetModPlayer <WoMDPlayer>(); if (player == null) { return; } for (int i = 0; i < tooltips.Count; i++) { if (tooltips[i].text.StartsWith("Current Tool: ")) { tooltips[i].text = "Current Tool: " + getPaintToolName(player.paintData.paintMethod); } else if (tooltips[i].text.StartsWith("Current Paint: ")) { tooltips[i].text = "Current Paint: " + getPaintColorName(player.paintData); } } base.ModifyTooltips(tooltips); }
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) { WoMDNPC npc = target.GetGlobalNPC <WoMDNPC>(); WoMDPlayer player = getModPlayer(projectile.owner); if (npc != null && player != null) { PaintMethods method = player.paintData.paintMethod; if (method != PaintMethods.None) { if (method == PaintMethods.RemovePaint) { npc.painted = false; int index = target.FindBuffIndex(BuffType <Painted>()); if (index >= 0) { target.DelBuff(index); } } else { applyPaintedToNPC(target, new PaintData(npcCyclingTimeScale, player.paintData.PaintColor, player.paintData.CustomPaint, player.paintData.CustomPaint is ISprayPaint, Main.GlobalTime, player: player.player)); } } } if (projectile.penetrate == 1) { onKillOnNPC(target); } }
protected override Texture2D getTexture(WoMDPlayer player) { if ((player.paintData.PaintColor == -1 && player.paintData.CustomPaint == null) || player.paintData.paintMethod == PaintMethods.RemovePaint) { return(null); } return(getExtraTexture("InfinitePaintSolutionPainted")); }
protected Texture2D getTexture(string itemname, WoMDPlayer player) { if (player.paintData.PaintColor == -1 && player.paintData.CustomPaint == null) { return(null); } return(getExtraTexture(itemname + "Painted")); }
protected override Texture2D getTexture(WoMDPlayer player) { if (player.paintData.PaintColor == -1 && player.paintData.CustomPaint == null) { return(null); } return(getExtraTexture(GetType().Name + "Painted")); }
protected override Texture2D getTexture(WoMDPlayer player) { //Needs to be overridden in this class, because the texture names do not follow the convention of <Class name>Painted if ((player.paintData.PaintColor == -1 && player.paintData.CustomPaint == null) || player.paintData.paintMethod == PaintMethods.RemovePaint) { return(null); } return(getExtraTexture("PaintShurikenPainted")); }
public override bool UseItem(Item item, Player player) { PaintMethods method; switch (item.type) { case ItemID.Paintbrush: case ItemID.SpectrePaintbrush: method = PaintMethods.Blocks; break; case ItemID.PaintRoller: case ItemID.SpectrePaintRoller: method = PaintMethods.Walls; break; case ItemID.PaintScraper: case ItemID.SpectrePaintScraper: method = PaintMethods.RemovePaint; break; default: return(false); } WoMDPlayer p = player.GetModPlayer <WoMDPlayer>(); if (p == null) { return(true); } Point coords; if (Main.SmartCursorEnabled) { coords = new Point(Main.SmartCursorX, Main.SmartCursorY); } else { coords = Main.MouseWorld.ToTileCoordinates(); Point playerPos = player.position.ToTileCoordinates(); int xOffset = coords.X - playerPos.X; int yOffset = coords.Y - playerPos.Y; if (yOffset < 0) { yOffset--; } if (!isInRange(player, xOffset, yOffset, item)) { return(false); } } PaintData data = p.paintData.clone(); data.TimeScale = paintCyclingTimeScale; data.paintMethod = method; paint(coords.X, coords.Y, data, true); return(true); }
/// <summary> /// Updates the colorFrame property /// </summary> public void updateColorFrame(PaintMethods method) { if (npcOwner == -1) { WoMDPlayer player = getModPlayer(projectile.owner); if (player != null) { if (player.paintData.PaintColor == -1 && player.paintData.CustomPaint == null) { colorFrame = 0; } else if (player.paintData.CustomPaint == null) { colorFrame = (byte)player.paintData.PaintColor; } else { colorFrame = player.paintData.CustomPaint.getPaintID(player.paintData); } } } else { NPC npc = getNPC(npcOwner); if (npc == null) { return; } WoMDNPC gNpc = npc.GetGlobalNPC <WoMDNPC>(); if (gNpc == null) { return; } PaintData data = gNpc.paintData; if (data == null) { colorFrame = 0; } else { if (data.PaintColor == -1 && data.CustomPaint == null) { colorFrame = 0; } else if (data.CustomPaint == null) { colorFrame = (byte)data.PaintColor; } else { colorFrame = data.CustomPaint.getPaintID(data); } } } updateFrame(method); }
protected override Texture2D getTexture(WoMDPlayer player) { //Needs to be overridden in this class, because the texture names do not follow the convention of <Class name>Painted and <Class name>Scraper if (player.paintData.paintMethod == PaintMethods.RemovePaint) { return(getExtraTexture("ThrowingPaintbrushScraper")); } if (player.paintData.PaintColor == -1 && player.paintData.CustomPaint == null) { return(null); } return(getExtraTexture("ThrowingPaintbrushPainted")); }
public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) { WoMDPlayer player = getModPlayer(projectile.owner); if (player != null) { if (player.paintData.paintMethod == PaintMethods.None || player.paintData.paintMethod == PaintMethods.RemovePaint || (player.paintData.PaintColor == -1 && player.paintData.CustomPaint == null)) { damage = (int)Math.Round(damage * .5f); } } }
public override bool ConsumeItem(Item item, Player player) { if (item.paint > 0) { WoMDPlayer p = player.GetModPlayer <WoMDPlayer>(); if (p != null) { if (p.accPalette) { return(false); } } } return(base.ConsumeItem(item, player)); }
//This is where damage is cut in half if the player's current tool is a paint scraper or the player doesn't have any paint or tools in their inventory public override void ModifyWeaponDamage(Player player, ref float add, ref float mult, ref float flat) { WoMDPlayer p = player.GetModPlayer <WoMDPlayer>(); if (p == null) { return; } if (!p.canPaint()) { mult *= .5f; } else if (p.paintData.paintMethod == PaintMethods.RemovePaint) { mult *= .5f; } }
public PaintMethods getPaintMethod() { if (_overridePaintData != null) { return(_overridePaintData.paintMethod); } if (npcOwner != -1) { return(PaintMethods.BlocksAndWalls); } WoMDPlayer p = getModPlayer(projectile.owner); if (p == null) { return(PaintMethods.BlocksAndWalls); } return(p.paintData.paintMethod); }
//This is where shaders are applied to items to make them reflect the current paint and tool the player is using public override bool PreDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) { Player p = getPlayer(Main.myPlayer); if (p == null) { return(true); } WoMDPlayer player = p.GetModPlayer <WoMDPlayer>(); if (player == null) { return(true); } MiscShaderData shader = getShader(this, p); if ((usesGSShader || ((player.paintData.PaintColor == PaintID.Negative || player.paintData.CustomPaint is NegativeSprayPaint) && !(this is CustomPaint)))) { if (shader != null) { spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, (player.paintData.PaintColor == PaintID.Negative || player.paintData.CustomPaint is NegativeSprayPaint) ? SamplerState.LinearClamp : SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone, null, Main.UIScaleMatrix); // SpriteSortMode needs to be set to Immediate for shaders to work. shader.Apply(); } Texture2D texture = getTexture(player); if (texture == null) { texture = Main.itemTexture[item.type]; } spriteBatch.Draw(texture, position, frame, drawColor, 0, new Vector2(0, 0), scale, SpriteEffects.None, 0); if (shader != null) { spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, null, Main.UIScaleMatrix); } return(false); } return(true); }
/// <summary> /// Determines whether or not the projectile is currently able to paint. /// </summary> /// <returns></returns> public bool canPaint() { if (_overridePaintData != null) { return(_overridePaintData.paintMethod != PaintMethods.None && (_overridePaintData.PaintColor != -1 || _overridePaintData.CustomPaint != null || _overridePaintData.paintMethod == PaintMethods.RemovePaint)); } if (npcOwner != -1) { return(true); } if (projectile.owner != Main.myPlayer) { return(false); } WoMDPlayer player = getModPlayer(projectile.owner); if (player == null) { return(false); } return(player.canPaint()); }
public override void ModifyTooltips(Item item, List <TooltipLine> tooltips) { switch (item.type) { case ItemID.Paintbrush: case ItemID.SpectrePaintbrush: case ItemID.PaintRoller: case ItemID.SpectrePaintRoller: Player p = getPlayer(item.owner); if (p == null) { return; } WoMDPlayer player = p.GetModPlayer <WoMDPlayer>(); if (player == null) { return; } tooltips.Add(new TooltipLine(player.mod, "CurrentPaintColor", "Current Color: " + getPaintColorName(player.paintData))); break; } }
public override PaintMethods overridePaintMethod(WoMDPlayer player) => PaintMethods.BlocksAndWalls;
public override bool PreDrawInInventory(Item item, SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) { PaintMethods method; string itemName; switch (item.type) { case ItemID.Paintbrush: itemName = "Paintbrush"; method = PaintMethods.Blocks; break; case ItemID.SpectrePaintbrush: itemName = "SpectrePaintbrush"; method = PaintMethods.Blocks; break; case ItemID.PaintRoller: itemName = "PaintRoller"; method = PaintMethods.Walls; break; case ItemID.SpectrePaintRoller: itemName = "SpectrePaintRoller"; method = PaintMethods.Walls; break; default: return(true); } Player p = getPlayer(item.owner); if (p == null) { return(true); } WoMDPlayer player = p.GetModPlayer <WoMDPlayer>(); if (player == null) { return(true); } Texture2D texture = getTexture(itemName, player); if (texture == null) { texture = Main.itemTexture[item.type]; } MiscShaderData shader = null; if (player.paintData.PaintColor != -1 || player.paintData.CustomPaint != null) { PaintData d = player.paintData.clone(); if (method != PaintMethods.None) { d.paintMethod = method; } shader = getShader(item.GetGlobalItem <WoMDItem>(), d); } spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, shader != null ? SamplerState.PointClamp : SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, null, Main.UIScaleMatrix); // SpriteSortMode needs to be set to Immediate for shaders to work. if (shader != null) { shader.Apply(); } spriteBatch.Draw(texture, position, frame, drawColor, 0, new Vector2(0, 0), scale, SpriteEffects.None, 0); if (shader != null) { spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, null, Main.UIScaleMatrix); } return(false); }
/// <summary> /// By default has no effect. Allows the item to override the paintMethod used for painting tiles. This is required for the Painting Multi-Tools to still work even if a different painting tool is found earlier in the player's inventory /// </summary> /// <param name="player"></param> /// <returns></returns> public virtual PaintMethods overridePaintMethod(WoMDPlayer player) => player.paintData.paintMethod;
/// <summary> /// Paints the tile at the given position /// </summary> /// <param name="x">The x coordinate of the tile. Expects values in tile coordinates</param> /// <param name="y">The y coordinate of the tile. Expects values in tile coordinates</param> /// <param name="color">The PaintID of the color to use</param> /// <param name="data">An instance of PaintData used to specify various settings for how painting should function</param> /// <param name="useWorldGen">Whether or not WorldGen.paintTile and WorldGen.paintWall should be used, or if the tile should just be modified directly. Using WorldGen causes additional visual effects</param> /// <returns>Whether or not the tile was updated</returns> private static bool paint(int x, int y, byte color, PaintData data, bool useWorldGen = false) { if (data.paintMethod == PaintMethods.None) { return(false); } if (data.sprayPaint) { if (WorldGen.genRand.NextFloat() < .6f) { return(false); } } if (!WorldGen.InWorld(x, y, 10)) { return(false); } Tile t = Main.tile[x, y]; if (t == null) { return(false); } if (data.paintMethod == PaintMethods.RemovePaint) { color = 0; } bool updated = false; if (data.paintMethod != PaintMethods.Walls && data.blocksAllowed && t.active() && t.color() != color && (color != 0 || data.paintMethod == PaintMethods.RemovePaint)) { if (useWorldGen) { WorldGen.paintTile(x, y, color, false); } else { t.color(color); } updated = true; } if (data.paintMethod != PaintMethods.Blocks && data.wallsAllowed && t.wall > 0 && t.wallColor() != color && (color != 0 || data.paintMethod == PaintMethods.RemovePaint)) { if (useWorldGen) { WorldGen.paintWall(x, y, color, false); } else { t.wallColor(color); } updated = true; } if (updated) { if (data.paintMethod != PaintMethods.RemovePaint && data.player != null && data.consumePaint) { WoMDPlayer player = data.player.GetModPlayer <WoMDPlayer>(); if (player != null) { player.consumePaint(data); } } if (server() || multiplayer()) { sendTileFrame(x, y); } } return(updated); }