rendered paste bodyusing System;
using System.Collections;
using System.Reflection;
using DOL.AI;
using DOL.AI.Brain;
using DOL.Events;
using DOL.Database;
using DOL.GS.PacketHandler;
using DOL.GS.Utils;
namespace DOL.GS.Scripts
{
[Cmd("&ngg", //command to handle
(uint) ePrivLevel.GM, //minimum privelege level
"NPC Gear Generator", //command description
"'/ngg random' Create a completely random equipment template",
"'/ngg cloth' Create a random set of cloth",
"'/ngg leather' Create a random set of leather",
"'/ngg studded' Create a random set of studded",
"'/ngg chain' Create a random set of chain",
"'/ngg scale' Create a random set of scale",
"'/ngg plate' Create a random set of plate",
"'/ngg cloak' Add a random cloak to the NPC",
"'/ngg save' Save the template and NPC to database"
)]
public class NGGCommandHandler : AbstractCommandHandler, ICommandHandler
{
/*
armor[0][][] = cloth;
armor[1][][] = leather;
armor[2][][] = studded;
armor[3][][] = chain;
armor[4][][] = scale;
armor[5][][] = plate;
armor[][0][] = head;
armor[][1][] = hands;
armor[][2][] = arms;
armor[][3][] = torso;
armor[][4][] = legs;
armor[][5][] = boots;
armor[][][x] = Model IDs;
cloak[x] = Model IDs;
*/
private static ushort[][][] armor = new ushort[6][][];
private static ushort[] cloak;
//private static String[] slots = {"head", "hands", "arms", "torso", "legs", "boots", "cloak"};
private static byte[] slots = { 0x15, 0x16, 0x1C, 0x19, 0x1B, 0x17, 0x1A };
[ScriptLoadedEvent]
public static void OnScriptCompiled(DOLEvent e, object sender, EventArgs args)
{
DataObject[] temp;
int[] ot = { 32, 33, 34, 35, 38, 36 };
int x;
for (int a = 0; a<6; a++)
{
armor[a] = new ushort[6][];
for (int b = 0; b<6; b++)
{
x = 0;
temp = GameServer.Database.SelectObjects(typeof(ItemTemplate), "Object_Type = " + ot[a] + " AND Item_Type = " + slots[b]);
armor[a][b] = new ushort[temp.Length];
foreach(DataObject item in temp)
{
armor[a][b][x++] = (ushort)(item as ItemTemplate).Model;
}
}
}
x = 0;
temp = GameServer.Database.SelectObjects(typeof(ItemTemplate), "Item_Type = " + slots[6]);
cloak = new ushort[temp.Length];
foreach(DataObject item in temp)
{
cloak[x++] = (ushort)(item as ItemTemplate).Model;
}
}
public int OnCommand(GameClient client, string[] args)
{
bool getcloak;
if(Util.Random(1) == 0) getcloak = false;
else getcloak = true;
if (args.Length != 2)
{
DisplaySyntax(client);
return 1;
}
GameNPC npc = null;
if (client.Player.TargetObject != null && client.Player.TargetObject is GameNPC)
npc = (GameNPC) client.Player.TargetObject;
GameNpcInventoryTemplate template = npc.Inventory as GameNpcInventoryTemplate;
if(template == null) template = new GameNpcInventoryTemplate();
switch(args[1])
{
case "random":
{
Clear(npc);
template = new GameNpcInventoryTemplate();
for(int i = 0; i<6; i++)
{
switch(Util.Random(5))
{
case 0:
template.AddNPCEquipment((eInventorySlot)slots[i], armor[0][i][Util.Random(armor[0][i].Length - 1)], Util.Random(86), 0);
break;
case 1:
template.AddNPCEquipment((eInventorySlot)slots[i], armor[1][i][Util.Random(armor[1][i].Length - 1)], Util.Random(86), 0);
break;
case 2:
template.AddNPCEquipment((eInventorySlot)slots[i], armor[2][i][Util.Random(armor[2][i].Length - 1)], Util.Random(86), 0);
break;
case 3:
template.AddNPCEquipment((eInventorySlot)slots[i], armor[3][i][Util.Random(armor[3][i].Length - 1)], Util.Random(86), 0);
break;
case 4:
template.AddNPCEquipment((eInventorySlot)slots[i], armor[4][i][Util.Random(armor[4][i].Length - 1)], Util.Random(86), 0);
break;
case 5:
template.AddNPCEquipment((eInventorySlot)slots[i], armor[5][i][Util.Random(armor[5][i].Length - 1)], Util.Random(86), 0);
break;
}
}
if(getcloak)
goto case "cloak";
else
break;
}
case "cloth":
{
Clear(npc);
template = new GameNpcInventoryTemplate();
template.AddNPCEquipment((eInventorySlot)slots[0], armor[0][0][Util.Random(armor[0][0].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[1], armor[0][1][Util.Random(armor[0][1].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[2], armor[0][2][Util.Random(armor[0][2].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[3], armor[0][3][Util.Random(armor[0][3].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[4], armor[0][4][Util.Random(armor[0][4].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[5], armor[0][5][Util.Random(armor[0][5].Length - 1)], Util.Random(86), 0);
if(getcloak)
goto case "cloak";
else
break;
}
case "leather":
{
Clear(npc);
template = new GameNpcInventoryTemplate();
template.AddNPCEquipment((eInventorySlot)slots[0], armor[1][0][Util.Random(armor[1][0].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[1], armor[1][1][Util.Random(armor[1][1].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[2], armor[1][2][Util.Random(armor[1][2].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[3], armor[1][3][Util.Random(armor[1][3].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[4], armor[1][4][Util.Random(armor[1][4].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[5], armor[1][5][Util.Random(armor[1][5].Length - 1)], Util.Random(86), 0);
if(getcloak)
goto case "cloak";
else
break;
}
case "studded":
{
Clear(npc);
template = new GameNpcInventoryTemplate();
template.AddNPCEquipment((eInventorySlot)slots[0], armor[2][0][Util.Random(armor[2][0].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[1], armor[2][1][Util.Random(armor[2][1].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[2], armor[2][2][Util.Random(armor[2][2].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[3], armor[2][3][Util.Random(armor[2][3].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[4], armor[2][4][Util.Random(armor[2][4].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[5], armor[2][5][Util.Random(armor[2][5].Length - 1)], Util.Random(86), 0);
if(getcloak)
goto case "cloak";
else
break;
}
case "chain":
{
Clear(npc);
template = new GameNpcInventoryTemplate();
template.AddNPCEquipment((eInventorySlot)slots[0], armor[3][0][Util.Random(armor[3][0].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[1], armor[3][1][Util.Random(armor[3][1].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[2], armor[3][2][Util.Random(armor[3][2].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[3], armor[3][3][Util.Random(armor[3][3].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[4], armor[3][4][Util.Random(armor[3][4].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[5], armor[3][5][Util.Random(armor[3][5].Length - 1)], Util.Random(86), 0);
if(getcloak)
goto case "cloak";
else
break;
}
case "scale":
{
Clear(npc);
template = new GameNpcInventoryTemplate();
template.AddNPCEquipment((eInventorySlot)slots[0], armor[4][0][Util.Random(armor[4][0].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[1], armor[4][1][Util.Random(armor[4][1].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[2], armor[4][2][Util.Random(armor[4][2].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[3], armor[4][3][Util.Random(armor[4][3].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[4], armor[4][4][Util.Random(armor[4][4].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[5], armor[4][5][Util.Random(armor[4][5].Length - 1)], Util.Random(86), 0);
if(getcloak)
goto case "cloak";
else
break;
}
case "plate":
{
Clear(npc);
template = new GameNpcInventoryTemplate();
template.AddNPCEquipment((eInventorySlot)slots[0], armor[5][0][Util.Random(armor[5][0].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[1], armor[5][1][Util.Random(armor[5][1].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[2], armor[5][2][Util.Random(armor[5][2].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[3], armor[5][3][Util.Random(armor[5][3].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[4], armor[5][4][Util.Random(armor[5][4].Length - 1)], Util.Random(86), 0);
template.AddNPCEquipment((eInventorySlot)slots[5], armor[5][5][Util.Random(armor[5][5].Length - 1)], Util.Random(86), 0);
if(getcloak)
goto case "cloak";
else
break;
}
case "cloak":
{
template.RemoveNPCEquipment((eInventorySlot)slots[6]);
template.AddNPCEquipment((eInventorySlot)slots[6], cloak[Util.Random(cloak.Length - 1)], Util.Random(86), 0);
break;
}
case "save":
{
Save(npc);
break;
}
default: DisplaySyntax(client); break;
}
npc.Inventory = template;
npc.UpdateNPCEquipmentAppearance();
return 1;
}
private void Clear(GameNPC target)
{
target.Inventory = null;
target.EquipmentTemplateID = null;
}
private void Save(GameNPC target)
{
String tn;
do
{
tn = System.Guid.NewGuid().ToString();
}while(!target.Inventory.SaveIntoDatabase(tn));
target.EquipmentTemplateID = tn;
target.SaveIntoDatabase();
}
}
}