Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using CookingMod.Items;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Graphics;
  6. using Terraria;
  7. using Terraria.ID;
  8. using Terraria.ObjectData;
  9. using Terraria.Localization;
  10. using Terraria.ModLoader;
  11. using Terraria.Utilities;
  12.  
  13. namespace CookingMod.NPCs
  14. {
  15.     public class Farmer : ModNPC
  16.     {
  17.         public override bool Autoload(ref string name) {
  18.             name = "Farmer";
  19.             return mod.Properties.Autoload;
  20.         }
  21.  
  22.         public override void SetStaticDefaults() {
  23.             Main.npcFrameCount[npc.type] = 25;
  24.             NPCID.Sets.ExtraFramesCount[npc.type] = 9;
  25.             NPCID.Sets.AttackFrameCount[npc.type] = 4;
  26.             NPCID.Sets.DangerDetectRange[npc.type] = 700;
  27.             NPCID.Sets.AttackType[npc.type] = 2;
  28.             NPCID.Sets.AttackTime[npc.type] = 8;
  29.             NPCID.Sets.AttackAverageChance[npc.type] = 30;
  30.             NPCID.Sets.HatOffsetY[npc.type] = 4;
  31.         }
  32.  
  33.         public override void SetDefaults() {
  34.             npc.townNPC = true;
  35.             npc.friendly = true;
  36.             npc.width = 18;
  37.             npc.height = 40;
  38.             npc.aiStyle = 7;
  39.             npc.damage = 10;
  40.             npc.defense = 15;
  41.             npc.lifeMax = 250;
  42.             npc.HitSound = SoundID.NPCHit1;
  43.             npc.DeathSound = SoundID.NPCDeath1;
  44.             npc.knockBackResist = 0.5f;
  45.             animationType = NPCID.Merchant;
  46.             TileObjectData.newTile.CopyFrom(TileObjectData.StyleAlch);
  47.         }
  48.  
  49.         public override void HitEffect(int hitDirection, double damage) {
  50.             int num = npc.life > 0 ? 1 : 5;
  51.         }
  52.  
  53.         public override bool CanTownNPCSpawn(int numTownNPCs, int money) {
  54.             for (int k = 0; k < 255; k++) {
  55.                 Player player = Main.player[k];
  56.                 if (!player.active) {
  57.                     continue;
  58.                 }
  59.  
  60.                 foreach (Item item in player.inventory) {
  61.                     if (item.type == mod.ItemType("EssenceOfCreature")) {
  62.                         return true;
  63.                     }
  64.                 }
  65.             }
  66.             return false;
  67.         }
  68.  
  69.         public override string TownNPCName() {
  70.             switch (WorldGen.genRand.Next(5)) {
  71.                 case 0:
  72.                     return "Hickory";
  73.                 case 1:
  74.                     return "Richard";
  75.                 case 2:
  76.                     return "Carl";
  77.                 case 3:
  78.                     return "Billy";
  79.                 default:
  80.                     return "Ferdinand";
  81.             }
  82.         }
  83.  
  84.         public override void FindFrame(int frameHeight) {
  85.             /*npc.frame.Width = 40;
  86.             if (((int)Main.time / 10) % 2 == 0)
  87.             {
  88.                 npc.frame.X = 40;
  89.             }
  90.             else
  91.             {
  92.                 npc.frame.X = 0;
  93.             }*/
  94.         }
  95.  
  96.         public override string GetChat()
  97.         {
  98.             WeightedRandom<string> chat = new WeightedRandom<string>();
  99.             int partyGirl = NPC.FindFirstNPC(NPCID.PartyGirl);
  100.             if (partyGirl >= 0 && Main.rand.NextBool(4))
  101.             {
  102.                 chat.Add("Can you remind " + Main.npc[partyGirl].GivenName + " that she still has my shotgun?");
  103.             }
  104.             if (Main.)
  105.             chat.Add("I'm pretty sure my cows keep escaping.");
  106.             chat.Add("Make it snappy. I've got work to do.");
  107.             chat.Add("I've heard legend of a gaint cow that's turned carnivore. Or maybe I saw it.. I can't remember");
  108.             chat.Add("Oh good, a sl... I mean worker. Grab a shovel and start helping.");
  109.             chat.Add("Where are you going with that money? Come and give me some of that!", 0.1);
  110.             return chat; // chat is implicitly cast to a string. You can also do "return chat.Get();" if that makes you feel better
  111.         }
  112.  
  113.         public override void SetChatButtons(ref string button, ref string button2) {
  114.             button = Language.GetTextValue("LegacyInterface.28");
  115.             button2 = "Animals";
  116.         }
  117.  
  118.         public override void OnChatButtonClicked(bool firstButton, ref bool shop) {
  119.             if (firstButton) {
  120.                 shop = true;
  121.             }
  122.             else {
  123.                 string[] animalCoins = new string[] {"Cow"};
  124.                 List<string> avAnimals = new List<string>();
  125.                 for(int a = 0; a < animalCoins.Length; a++){
  126.                     if (Main.LocalPlayer.HasItem(mod.ItemType(animalCoins[a] + "Coin"))) avAnimals.Add(animalCoins[a]);
  127.                 }
  128.                 if (avAnimals.Count > 0){
  129.                     var animal = Main.rand.Next(avAnimals.Count);
  130.                     var animalName = avAnimals[animal];
  131.                     Main.LocalPlayer.inventory[Main.LocalPlayer.FindItem(mod.ItemType(animalName + "Coin"))].TurnToAir();
  132.                     Main.npcChatText = "I spawned a " + (animalName.ToLower()) + " for a " + animalName.ToLower() + " coin!";
  133.                     NPC.NewNPC((int)npc.Left.X, (int)npc.Bottom.Y, mod.NPCType(animalName));
  134.                 }
  135.                 else {
  136.                     Main.npcChatText = "If you have animal coins, I can spawn that animal for you.";
  137.                 }
  138.             }
  139.         }
  140.  
  141.         public override void SetupShop(Chest shop, ref int nextSlot) {
  142.             shop.item[nextSlot].SetDefaults(mod.ItemType("CocoaSeeds"));
  143.             nextSlot++;
  144.             shop.item[nextSlot].SetDefaults(ItemID.Sickle);
  145.             nextSlot++;
  146.         }
  147.  
  148.         public override void TownNPCAttackStrength(ref int damage, ref float knockback) {
  149.             damage = 20;
  150.             knockback = 4f;
  151.         }
  152.  
  153.         public override void TownNPCAttackCooldown(ref int cooldown, ref int randExtraCooldown) {
  154.             cooldown = 30;
  155.             randExtraCooldown = 30;
  156.         }
  157.  
  158.         public override void TownNPCAttackProj(ref int projType, ref int attackDelay) {
  159.             projType = 93;
  160.             attackDelay = 1;
  161.         }
  162.  
  163.         public override void TownNPCAttackProjSpeed(ref float multiplier, ref float gravityCorrection, ref float randomOffset) {
  164.             multiplier = 12f;
  165.             randomOffset = 2f;
  166.         }
  167.     }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement