// TMW2 functions. // Author: // Jesusalva // Description: // Random Treasure Box Utils // TreasureBox ( { bonus chance{, TreasureKey} } ) function script TreasureBox { .@id=getnpcid(); if (RNGTREASURE_DATE[.@id] > gettimetick(2)) { mesc l("The chest is unlocked and empty."); close; } .@key=getarg(1, TreasureKey); mesc l("Open the chest?"); mesc l("Cost: 1 @@", getitemlink(.@key)), 1; if (!countitem(.@key)) close; next; if (askyesno() == ASK_NO) close; delitem .@key, 1; mesc l("You open the chest!"); RNGTREASURE_DATE[.@id]=gettimetick(2)+CHEST_WAITTIME; // Minimum 15 minutes .@empty=getvariableofnpc(.empty, strnpcinfo(0)); if (!.@empty) { TREASURE_OPEN=TREASURE_OPEN+1; .@t=TREASURE_OPEN; .@r=rand(0,10000)-(readparam2(bLuk)*2); // Some chests may have different rates // Note that rare is used as 300 instead of 200 // This is to normalize with SR/UR formula if (.@r > 1600) // UC and C (100% ~ 150% bonus) .@r-=max(getarg(0, 0), 1200)+min((.@r-1600), getarg(0, 0)/2); else if (.@r > 300) // Rare (67% ~ 120% bonus) .@r-=max(getarg(0, 0), 285)+min((.@r-300), getarg(0, 0)/5); else if (.@r <= 300) // SR and UR (67% Bonus) .@r-=getarg(0, 0)*2/3; // Select treasure list // You're warranted an ultra rare (0.1%) every 149 open chests // You're warranted a super rare (2%) every 50 open chests // There's also rares (14%), uncommons (36%) and commons (48%) .@ur_rate=min(15, (TREASURE_OPEN/10)); if (.@t % 149 == 0 || .@r < .@ur_rate) .@loot=any(ScrollMagnusHealC, SaviorBlueprint, DivineApple, MercBoxE, ScrollSDragon, Shemagh, Shemagh, EverburnPowder, IridiumOre, PlatinumOre, SacredImmortalityPotion, MagicApple, ElixirOfLife); else if (.@t % 50 == 0 || .@r < 200) .@loot=any(MercBoxC, ScrollMagnusHealB, SnakeEgg, LachesisBrew, ArrowAmmoBox, GoldPieces, SilverGift, TerraniteOre, LeadOre, TinOre, SilverOre, GoldOre, TitaniumOre, FluoPowder, Lockpicks, EquipmentBlueprintC, AlchemyBlueprintC, AlchemyBlueprintD, AncientBlueprint, YerbaMate, JasmineTea, DeathPotion, SacredLifePotion, SacredManaPotion, BrokenWarpCrystal, PurificationPotion, GoldenApple); else if (.@r < 1600 || .@t == 0) .@loot=any(MercBoxB, MoubooSteak, SmokeGrenade, ClothoLiquor, Coal, RedPlushWine, PrecisionPotion, CoinBag, DodgePotion, MoveSpeedPotion, Dagger, BronzeGift, IronOre, CopperOre, BlueDye, EquipmentBlueprintB, AlchemyBlueprintB, AlchemyBlueprintC, OolongTea); else if (.@r < 5200) .@loot=any(MercBoxA, Croconut, Potatoz, MoubooSteak, ClothoLiquor, Coal, SmallMushroom, HastePotion, StrengthPotion, WoodenLog, LeatherPatch, Beer, StrangeCoin, EquipmentBlueprintA, EquipmentBlueprintB, AlchemyBlueprintA, SpearmintTea, TreasureMap, DungeonMap, IcedBottle); else .@loot=any(FatesPotion, PiberriesInfusion, EmptyBottle, ChocolateBar, Plushroom, Chagashroom, RawLog, LeatherPatch, BugLeg, ScorpionStinger, SmallKnife, ChamomileTea, EquipmentBlueprintA); inventoryplace .@loot, 1; mesc l("You find @@ inside!", getitemlink(.@loot)); getitem .@loot, 1; // Get Monster points for treasure hunting (20% from job level) if (MPQUEST) Mobpt+=(JobLevel/5); // World Expo Event if ($EVENT$ == "Expo") FYE_Expo(); } else { mesc l("You find @@ inside!", l("nothing")); } X24Event(X24_GROUP3, X24_G3_TREASURE); return; } ////////////////////////////// // Dungeon's Points Of Interest // A Point Of Interest is a temporary duplicate NPC which is randomly // created & assigned to key points and contains minor stuff you can loot. // #DungeonPOI controls the duplication, and #DungeonPOI_Type<%02d> is the type /* Type 1 : Thrash */ boss,0,0,0 script #DungeonPOI_Type01 NPC_NO_SPRITE,0,0,{ OnTalk: // Someone already looted this before you if (.empty) end; // You are the first one looting this, so provision space inventoryplace NPCEyes, 1; inventoryplace Iten, 1; // No one else can now loot this .empty = true; // Retrieve the item from Type 1 list // relative_array_random() setarray(.@prizes, 0, TolchiAmmoBox, 100, TrainingAmmoBox, 75, ArrowAmmoBox, 50, IronAmmoBox, 35, BigArrowSack, 20, MysteriousBottle, 7, SmokeGrenade, 7, IronPowder, 3, CottonCloth, 6, TreasureKey, 60, StrangeCoin, 1, PileOfAsh, 5, EverburnPowder, 2, EarthPowder, 2, ShadowHerb, 3 ); // Some are conditional unlocks if ($ARKIM_ST >= 1400) { array_push(.@prizes, CursedAmmoBox); array_push(.@prizes, 25); } if ($ARKIM_ST >= 2800) { array_push(.@prizes, PoisonAmmoBox); array_push(.@prizes, 15); } if ($ARKIM_ST >= 10000 && $GAME_STORYLINE >= 4) { array_push(.@prizes, ThornAmmoBox); array_push(.@prizes, 5); } if ($ARKIM_ST >= 10000 && $GAME_STORYLINE >= 5) { array_push(.@prizes, BoneAmmoBox); array_push(.@prizes, 1); } // Story-limited content if ($GAME_STORYLINE < 5) { array_push(.@prizes, EmptyBottle); array_push(.@prizes, 5); array_push(.@prizes, MintDonut); array_push(.@prizes, 4); array_push(.@prizes, ChocolateDonut); array_push(.@prizes, 4); array_push(.@prizes, StrawberryDonut); array_push(.@prizes, 4); array_push(.@prizes, ScrollBattlePlansA); array_push(.@prizes, 2); array_push(.@prizes, ScrollCriticalFortuneA); array_push(.@prizes, 2); } else { array_push(.@prizes, MintDonut); array_push(.@prizes, 2); array_push(.@prizes, ChocolateDonut); array_push(.@prizes, 2); array_push(.@prizes, StrawberryDonut); array_push(.@prizes, 2); array_push(.@prizes, EmptyBottle); array_push(.@prizes, 2); } // Decide what you'll find this time .@item = relative_array_random(.@prizes); dispbottom l("You've found a(n) %s.", getitemname(.@item)); getitem .@item, 1; // Expire the instance as soon as reasonable .@t = htget($@_DUPES, .name$, 0); if (.@t) { .@t = min(gettimetick(2)+2, .@t); htput($@_DUPES, .name$, .@t); } end; OnInit: .distance = 1; .empty = false; end; } /* Type 2 : Food */ boss,0,0,0 script #DungeonPOI_Type02 NPC_NO_SPRITE,0,0,{ OnTalk: // Someone already looted this before you if (.empty) end; // You are the first one looting this, so provision space inventoryplace NPCEyes, 1; inventoryplace Iten, 1; // No one else can now loot this .empty = true; // Retrieve the item from Type 2 list // relative_array_random() setarray(.@prizes, 0, Bread, 10, Tomato, 8, Potatoz, 6, ChickenLeg, 5, Cheese, 5, Curshroom, 3, MoubooSteak, 3, SnakeEgg, 2, Orange, 1, Pear, 1, TonoriDelight, 1 ); // Decide what you'll find this time .@item = relative_array_random(.@prizes); dispbottom l("You've found a(n) %s.", getitemname(.@item)); getitem .@item, 1; // Expire the instance as soon as reasonable .@t = htget($@_DUPES, .name$, 0); if (.@t) { .@t = min(gettimetick(2)+2, .@t); htput($@_DUPES, .name$, .@t); } end; OnInit: .distance = 1; .empty = false; end; } /* Type 3 : Low Garbage */ boss,0,0,0 script #DungeonPOI_Type03 NPC_NO_SPRITE,0,0,{ OnTalk: // Someone already looted this before you if (.empty) end; // You are the first one looting this, so provision space inventoryplace NPCEyes, 1; inventoryplace Iten, 1; // No one else can now loot this .empty = true; // Retrieve the item from Type 2 list // relative_array_random() setarray(.@prizes, 0, TolchiArrow, 7, TrainingArrow, 6, Plushroom, 6, BugLeg, 5, Manana, 3, Piberries, 3, CottonCloth, 1, Roach, 1 ); // Decide what you'll find this time .@item = relative_array_random(.@prizes); dispbottom l("You've found a(n) %s.", getitemname(.@item)); getitem .@item, 1; // Expire the instance as soon as reasonable .@t = htget($@_DUPES, .name$, 0); if (.@t) { .@t = min(gettimetick(2)+2, .@t); htput($@_DUPES, .name$, .@t); } end; OnInit: .distance = 1; .empty = false; end; } // Core logic - script #DungeonPOI NPC_HIDDEN,{ function create_poi; function p; end; OnInit: .offset = 0; OnClock0551: OnClock1751: // Sanitization: Ensure the duplication database exists (OnInterIfInit) if (!$@_DUPES) end; // 026-2 Impregnable Fortress B2F create_poi("026-2", 44, 30, 1, p(15)); create_poi("026-2", 89, 57, 1, p(15)); create_poi("026-2", 95, 68, 1, p(15)); create_poi("026-2", 48, 89, 1, p(15)); create_poi("026-2", 32, 68, 1, p(15)); create_poi("026-2", 27, 50, 1, p(15)); // 026-0 Impregnable Fortress B0F create_poi("026-0", 91, 69, 2, p(100)); create_poi("026-0", 29, 38, 1, p(15)); create_poi("026-0", 89, 25, 1, p(30)); create_poi("026-0", 97, 25, 1, p(30)); // 027-7 Magic Academy Storage Room create_poi("027-7", 34, 41, 1, p(5)); create_poi("027-7", 36, 41, 1, p(5)); create_poi("027-7", 31, 41, 1, p(5)); create_poi("027-7", 34, 41, 1, p(5)); create_poi("027-7", 23, 40, 2, p(5)); create_poi("027-7", 51, 41, 1, p(5)); // Sack create_poi("027-7", 34, 32, 1, p(5)); create_poi("027-7", 36, 32, 1, p(5)); create_poi("027-7", 21, 32, 1, p(5)); create_poi("027-7", 27, 20, 1, p(5)); create_poi("027-7", 34, 20, 1, p(5)); create_poi("027-7", 46, 20, 1, p(5)); create_poi("027-7", 48, 20, 1, p(5)); create_poi("027-7", 58, 20, 1, p(5)); // 015-2 Bandit Cave create_poi("015-2", 264, 172, 1, p(40)); create_poi("015-2", 266, 170, 1, p(10)); create_poi("015-2", 247, 233, 1, p(40)); create_poi("015-2", 244, 237, 1, p(20)); create_poi("015-2", 260, 237, 1, p(60)); if ($GAME_STORYLINE >= 4) create_poi("015-2", 262, 246, 2, p(20)); // I have no idea how Kamelot would behave to this!! // Same for Gemini Sisters // Tests must be done first end; // p({base}) aka. probability given storyline step (with rounding) function p { return getarg(0) * min(5, max(1, $GAME_STORYLINE)) / 5; } // create_poi(map, x, y, type, probability) function create_poi { if (rand2(100) > getarg(4)) return; .offset += 1; .@n$ = sprintf("#POI_%06d_%02d_%03d", .offset, .@id, htsize($@_DUPES)); .@m$ = getarg(0); .@x = getarg(1); .@y = getarg(2); .@id = getarg(3); npc_duplicate(sprintf("#DungeonPOI_Type%02d", .@id), .@n$, .@m$, .@x, .@y, NPC_NO_SPRITE, 0, 0, 0); htput($@_DUPES, .@n$, gettimetick(2) + 43200); return; } } // Artifical PoI for pre-existing NPCs // Must, however, handle .empty manually. Returns TRUE if it'll be searched. // FakePoI( type=01, conditional=true ) function script FakePoI { .@type = getarg(0, 1); .@cond = getarg(1, true); if (!.@cond) return false; doevent(sprintf("#DungeonPOI_Type%02d::OnTalk", .@type)); return true; }