本文整理汇总了C#中DOL.GS.GameNPC类的典型用法代码示例。如果您正苦于以下问题:C# GameNPC类的具体用法?C# GameNPC怎么用?C# GameNPC使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GameNPC类属于DOL.GS命名空间,在下文中一共展示了GameNPC类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMoneyTask
public void CreateMoneyTask()
{
GamePlayer player = CreateMockGamePlayer();
GameMerchant merchant = new GameMerchant();
merchant.Name = "Tester";
merchant.Realm = eRealm.Albion;
Console.WriteLine(player.Name);
if (MoneyTask.CheckAvailability(player, merchant))
{
if (MoneyTask.BuildTask(player, merchant))
{
MoneyTask task = (MoneyTask)player.Task;
Assert.IsNotNull(task);
Console.WriteLine("XP" + task.RewardXP);
Console.WriteLine("Item:" + task.ItemName);
Console.WriteLine("Item:" + task.Name);
Console.WriteLine("Item:" + task.Description);
// Check Notify Event handling
InventoryItem item = GameInventoryItem.Create(new ItemTemplate());
item.Name = task.ItemName;
GameNPC npc = new GameNPC();
npc.Name = task.RecieverName;
task.Notify(GamePlayerEvent.GiveItem, player, new GiveItemEventArgs(player, npc, item));
if (player.Task.TaskActive || player.Task == null)
Assert.Fail("Task did not finished proper in Notify");
}
}
}
示例2: ScriptLoaded
public static void ScriptLoaded(DOLEvent e, object sender, EventArgs args)
{
if (!ServerProperties.Properties.LOAD_EXAMPLES)
return;
#region defineNPCs
GameNPC[] npcs = WorldMgr.GetNPCsByName("Sir Quait", eRealm.Albion);
npcs = WorldMgr.GetNPCsByName("Sir Quait", (eRealm)1);
GameNPC SirQuait = null;
if (npcs.Length == 0)
{
SirQuait = new DOL.GS.GameNPC();
SirQuait.Model = 40;
SirQuait.Name = "Sir Quait";
if (log.IsWarnEnabled)
log.Warn("Could not find " + SirQuait.Name + ", creating ...");
SirQuait.Realm = eRealm.Albion;
SirQuait.CurrentRegionID = 1;
SirQuait.Size = 50;
SirQuait.Level = 10;
SirQuait.MaxSpeedBase = 100;
SirQuait.Faction = FactionMgr.GetFactionByID(0);
SirQuait.X = 531971;
SirQuait.Y = 478955;
SirQuait.Z = 0;
SirQuait.Heading = 3570;
SirQuait.RespawnInterval = 0;
SirQuait.BodyType = 0;
StandardMobBrain brain = new StandardMobBrain();
brain.AggroLevel = 0;
brain.AggroRange = 0;
SirQuait.SetOwnBrain(brain);
SirQuait.AddToWorld();
}
else
{
SirQuait = npcs[0];
}
#endregion
#region defineBehaviours
BaseBehaviour b = new BaseBehaviour(SirQuait);
MessageAction a = new MessageAction(SirQuait,"This is just a simple test bahaviour.",eTextType.Emote);
b.AddAction(a);
InteractTrigger t = new InteractTrigger(SirQuait,b.NotifyHandler,SirQuait);
b.AddTrigger(t);
// store the behaviour in a list so it won't be garbage collected
behaviours.Add(b);
#endregion
log.Info("Simple Test Behaviour added");
}
示例3: CreateKillTask
public void CreateKillTask()
{
GamePlayer player = CreateMockGamePlayer();
player.Level=5;
player.AddToWorld();
// Trainer for taks
GameTrainer trainer = new GameTrainer();
trainer.Name ="Tester";
Console.WriteLine(player.Name);
// player must have trainer selected when task given.
player.TargetObject = trainer;
// mob for task
if (KillTask.BuildTask(player,trainer))
{
KillTask task =(KillTask) player.Task;
Assert.IsNotNull(task);
Assert.IsTrue(task.TaskActive);
Console.WriteLine("Mob:"+ task.MobName);
Console.WriteLine("Item:"+ task.ItemName);
Console.WriteLine(""+ task.Description);
// Check Notify Event handling
InventoryItem item = GameInventoryItem.Create<ItemTemplate>(new ItemTemplate());
item.Name = task.ItemName;
GameNPC mob = new GameNPC();
mob.Name = task.MobName;
mob.X = player.X;
mob.Y = player.Y;
mob.Z = player.Z;
mob.Level = player.Level;
mob.CurrentRegionID = player.CurrentRegionID;
mob.AddToWorld();
// First we kill mob
mob.XPGainers.Add(player,1.0F);
task.Notify(GameNPCEvent.EnemyKilled,player,new EnemyKilledEventArgs(mob));
// arificial pickup Item
player.Inventory.AddItem(eInventorySlot.FirstEmptyBackpack, item);
// Check item in Inventory
if (player.Inventory.GetFirstItemByName(task.ItemName,eInventorySlot.FirstBackpack,eInventorySlot.LastBackpack) != null)
Assert.Fail("Player didn't recieve task item.");
// Now give item tro trainer
task.Notify(GamePlayerEvent.GiveItem,player,new GiveItemEventArgs(player,trainer,item));
if (player.Task.TaskActive || player.Task==null)
Assert.Fail("Task did not finished proper in Notify");
}
}
示例4: AddRemoveObjects
public void AddRemoveObjects()
{
const int count = 30000;
GameNPC[] mobs = new GameNPC[count];
Console.Out.WriteLine("[{0}] init {1} mobs", id, count);
// init mobs
for (int i = 0; i < count; i++)
{
GameNPC mob = mobs[i] = new GameNPC();
Assert.IsTrue(mob.ObjectID == -1, "mob {0} oid={1}, should be -1", i, mob.ObjectID);
Assert.IsFalse(mob.ObjectState == GameObject.eObjectState.Active, "mob {0} state={1}, should be not Active", i, mob.ObjectState);
mob.Name = "test mob " + i;
mob.CurrentRegion = m_reg;
m_reg.PreAllocateRegionSpace(1953);
}
for (int x = 10; x > 0; x--)
{
Console.Out.WriteLine("[{0}] loop {1} add mobs", id, count-x);
// add mobs
for (int i = 0; i <= count-x; i++)
{
// Console.Out.WriteLine("add "+i);
GameNPC mob = mobs[i];
Assert.IsTrue(mob.AddToWorld(), "failed to add {0} to the world", mob.Name);
Assert.IsTrue(mob.ObjectID > 0 && mob.ObjectID <= DOL.GS.ServerProperties.Properties.REGION_MAX_OBJECTS, "{0} oid={1}", mob.Name, mob.ObjectID);
}
for (int i = count-x; i >= 0; i--)
{
// Console.Out.WriteLine("check "+i);
GameNPC mob = mobs[i];
GameNPC regMob = (GameNPC)m_reg.GetObject((ushort)mob.ObjectID);
Assert.AreSame(mob, regMob, "expected to read '{0}' oid={1} but read '{2}' oid={3}", mob.Name, mob.ObjectID, regMob==null?"null":regMob.Name, regMob==null?"null":regMob.ObjectID.ToString());
}
Console.Out.WriteLine("[{0}] loop {1} remove mobs", id, count-x);
// remove mobs
for (int i = count-x; i >= 0; i--)
{
// Console.Out.WriteLine("remove "+i);
GameNPC mob = mobs[i];
int oid = mob.ObjectID;
Assert.IsTrue(mob.RemoveFromWorld(), "failed to remove {0}", mob.Name);
Assert.IsTrue(mob.ObjectID == -1, "{0}: oid is not -1 (oid={1})", mob.Name, mob.ObjectID);
Assert.IsFalse(mob.ObjectState == GameObject.eObjectState.Active, "{0} is still active after remove", mob.Name);
GameNPC regMob = (GameNPC)m_reg.GetObject((ushort)oid);
Assert.IsNull(regMob, "{0} was removed from the region but oid {1} is still used by {2}", mob.Name, oid, regMob==null?"null":regMob.Name);
}
}
}
示例5: AddObject
[Test] public void AddObject()
{
Region region = WorldMgr.GetRegion(1);
GameObject obj = new GameNPC();
obj.Name="TestObject";
obj.X = 400000;
obj.Y = 200000;
obj.Z = 2000;
obj.CurrentRegion = region;
obj.AddToWorld();
if (obj.ObjectID<0)
Assert.Fail("Failed to add object to Region. ObjectId < 0");
Assert.AreEqual(region.GetObject((ushort)obj.ObjectID),obj);
}
示例6: TestLootGenerator
public void TestLootGenerator()
{
GameNPC mob = new GameNPC();
mob.Level = 6;
mob.Name="impling";
for (int i=0;i< 15; i++)
{
Console.WriteLine("Loot "+i);
ItemTemplate[] loot = LootMgr.GetLoot(mob, null);
foreach (ItemTemplate item in loot)
{
Console.WriteLine(mob.Name+" drops "+item.Name);
}
}
Console.WriteLine("Drops finished");
}
示例7: StartSpell
/// <summary>
/// called when spell effect has to be started and applied to targets
/// </summary>
public override bool StartSpell(GameLiving target)
{
if (m_charmedNpc == null)
m_charmedNpc = target as GameNPC; // save target on first start
else
target = m_charmedNpc; // reuse for pulsing spells
if (target == null) return false;
if (Util.Chance(CalculateSpellResistChance(target)))
{
OnSpellResisted(target);
}
else
{
ApplyEffectOnTarget(target, 1);
}
return true;
}
示例8: AccountVault
/// <summary>
/// An account vault that masquerades as a house vault to the game client
/// </summary>
/// <param name="player">Player who owns the vault</param>
/// <param name="vaultNPC">NPC controlling the interaction between player and vault</param>
/// <param name="vaultOwner">ID of vault owner (can be anything unique, if it's the account name then all toons on account can access the items)</param>
/// <param name="vaultNumber">Valid vault IDs are 0-3</param>
/// <param name="dummyTemplate">An ItemTemplate to satisfy the base class's constructor</param>
public AccountVault(GamePlayer player, GameNPC vaultNPC, string vaultOwner, int vaultNumber, ItemTemplate dummyTemplate)
: base(dummyTemplate, vaultNumber)
{
m_player = player;
m_vaultNPC = vaultNPC;
m_vaultOwner = vaultOwner;
m_vaultNumber = vaultNumber;
DBHouse dbh = new DBHouse();
//was allowsave = false but uhh i replaced with allowadd = false
dbh.AllowAdd = false;
dbh.GuildHouse = false;
dbh.HouseNumber = player.ObjectID;
dbh.Name = player.Name + "'s House";
dbh.OwnerID = player.DBCharacter.ObjectId;
dbh.RegionID = player.CurrentRegionID;
CurrentHouse = new House(dbh);
}
示例9: LockRelic
public static bool LockRelic()
{
//make sure the relic exists before you lock it!
if (Relic == null)
return false;
LockedEffect = new GameNPC();
LockedEffect.Model = 1583;
LockedEffect.Name = "LOCKED_RELIC";
LockedEffect.X = Relic.X;
LockedEffect.Y = Relic.Y;
LockedEffect.Z = Relic.Z;
LockedEffect.Heading = Relic.Heading;
LockedEffect.CurrentRegionID = Relic.CurrentRegionID;
LockedEffect.Flags = GameNPC.eFlags.CANTTARGET;
LockedEffect.AddToWorld();
return true;
}
示例10: GenerateLoot
/// <summary>
/// Generate loot for given mob
/// </summary>
/// <param name="mob"></param>
/// <param name="killer"></param>
/// <returns></returns>
public override LootList GenerateLoot(GameNPC mob, GameObject killer)
{
LootList loot = base.GenerateLoot(mob, killer);
int lvl = mob.Level + 1;
if (lvl < 1) lvl = 1;
int minLoot = 2 + ((lvl * lvl * lvl) >> 3);
long moneyCount = minLoot + Util.Random(minLoot >> 1);
moneyCount = (long)((double)moneyCount * ServerProperties.Properties.MONEY_DROP);
ItemTemplate money = new ItemTemplate();
money.Model = 488;
money.Name = "bag of coins";
money.Level = 0;
money.Price = moneyCount;
loot.AddFixed(money, 1);
return loot;
}
示例11: GenerateLoot
/// <summary>
/// Generate loot for given mob
/// </summary>
/// <param name="mob"></param>
/// <param name="killer"></param>
/// <returns></returns>
public override LootList GenerateLoot(GameNPC mob, GameObject killer)
{
LootList loot = base.GenerateLoot(mob, killer);
try
{
GamePlayer player = killer as GamePlayer;
if (killer is GameNPC && ((GameNPC)killer).Brain is IControlledBrain)
player = ((ControlledNpcBrain)((GameNPC)killer).Brain).GetPlayerOwner();
if (player == null)
return loot;
ItemTemplate atlanteanGlass = new ItemTemplate(m_atlanteanglass);
int killedcon = (int)player.GetConLevel(mob)+3;
if(killedcon <= 0)
return loot;
int lvl = mob.Level + 1;
if (lvl < 1) lvl = 1;
int maxcount = 1;
//Switch pack size
if (lvl > 0 && lvl < 10)
{
//Single AtlanteanGlass
maxcount = (int)Math.Floor((double)(lvl/2))+1;
}
else if (lvl >= 10 && lvl < 20)
{
//Double
atlanteanGlass.PackSize = 2;
maxcount = (int)Math.Floor((double)((lvl-10)/2))+1;
}
else if (lvl >= 20 && lvl < 30)
{
//Triple
atlanteanGlass.PackSize = 3;
maxcount = (int)Math.Floor((double)((lvl-20)/2))+1;
}
else if (lvl >=30 && lvl < 40)
{
//Quad
atlanteanGlass.PackSize = 4;
maxcount = (int)Math.Floor((double)((lvl-30)/2))+1;
}
else if (lvl >= 40 && lvl < 50)
{
//Quint
atlanteanGlass.PackSize = 5;
maxcount = (int)Math.Floor((double)((lvl-40)/2))+1;
}
else
{
//Cache (x10)
atlanteanGlass.PackSize = 10;
maxcount = (int)Math.Round((double)(lvl/10));
}
if (!mob.Name.ToLower().Equals(mob.Name))
{
//Named mob, more cash !
maxcount = (int)Math.Round(maxcount*ServerProperties.Properties.LOOTGENERATOR_ATLANTEANGLASS_NAMED_COUNT);
}
if(maxcount > 0 && Util.Chance(ServerProperties.Properties.LOOTGENERATOR_ATLANTEANGLASS_BASE_CHANCE+Math.Max(10, killedcon)))
{
loot.AddFixed(atlanteanGlass, maxcount);
}
}
catch
{
return loot;
}
return loot;
}
示例12: CastingBehaviour
public CastingBehaviour(GameNPC body)
{
Body = body;
}
示例13: Copy
/// <summary>
/// Create a copy of the GameNPC
/// </summary>
/// <param name="copyTarget">A GameNPC to copy this GameNPC to (can be null)</param>
/// <returns>The GameNPC this GameNPC was copied to</returns>
public GameNPC Copy( GameNPC copyTarget )
{
if ( copyTarget == null )
copyTarget = new GameNPC();
copyTarget.TranslationId = TranslationId;
copyTarget.BlockChance = BlockChance;
copyTarget.BodyType = BodyType;
copyTarget.CanUseLefthandedWeapon = CanUseLefthandedWeapon;
copyTarget.Charisma = Charisma;
copyTarget.Constitution = Constitution;
copyTarget.CurrentRegion = CurrentRegion;
copyTarget.Dexterity = Dexterity;
copyTarget.Empathy = Empathy;
copyTarget.Endurance = Endurance;
copyTarget.EquipmentTemplateID = EquipmentTemplateID;
copyTarget.EvadeChance = EvadeChance;
copyTarget.Faction = Faction;
copyTarget.Flags = Flags;
copyTarget.GuildName = GuildName;
copyTarget.ExamineArticle = ExamineArticle;
copyTarget.MessageArticle = MessageArticle;
copyTarget.Heading = Heading;
copyTarget.Intelligence = Intelligence;
copyTarget.IsCloakHoodUp = IsCloakHoodUp;
copyTarget.IsCloakInvisible = IsCloakInvisible;
copyTarget.IsHelmInvisible = IsHelmInvisible;
copyTarget.LeftHandSwingChance = LeftHandSwingChance;
copyTarget.Level = Level;
copyTarget.LoadedFromScript = LoadedFromScript;
copyTarget.MaxSpeedBase = MaxSpeedBase;
copyTarget.MeleeDamageType = MeleeDamageType;
copyTarget.Model = Model;
copyTarget.Name = Name;
copyTarget.Suffix = Suffix;
copyTarget.NPCTemplate = NPCTemplate;
copyTarget.ParryChance = ParryChance;
copyTarget.PathID = PathID;
copyTarget.PathingNormalSpeed = PathingNormalSpeed;
copyTarget.Quickness = Quickness;
copyTarget.Piety = Piety;
copyTarget.Race = Race;
copyTarget.Realm = Realm;
copyTarget.RespawnInterval = RespawnInterval;
copyTarget.RoamingRange = RoamingRange;
copyTarget.Size = Size;
copyTarget.SaveInDB = SaveInDB;
copyTarget.Strength = Strength;
copyTarget.TetherRange = TetherRange;
copyTarget.MaxDistance = MaxDistance;
copyTarget.X = X;
copyTarget.Y = Y;
copyTarget.Z = Z;
copyTarget.OwnerID = OwnerID;
copyTarget.PackageID = PackageID;
if ( Abilities != null && Abilities.Count > 0 )
{
foreach (Ability targetAbility in Abilities.Values)
{
if ( targetAbility != null )
copyTarget.AddAbility( targetAbility );
}
}
ABrain brain = null;
foreach ( Assembly assembly in AppDomain.CurrentDomain.GetAssemblies() )
{
brain = (ABrain)assembly.CreateInstance( Brain.GetType().FullName, true );
if ( brain != null )
break;
}
if ( brain == null )
{
log.Warn( "GameNPC.Copy(): Unable to create brain: " + Brain.GetType().FullName + ", using StandardMobBrain." );
brain = new StandardMobBrain();
}
StandardMobBrain newBrainSMB = brain as StandardMobBrain;
StandardMobBrain thisBrainSMB = this.Brain as StandardMobBrain;
if ( newBrainSMB != null && thisBrainSMB != null )
{
newBrainSMB.AggroLevel = thisBrainSMB.AggroLevel;
newBrainSMB.AggroRange = thisBrainSMB.AggroRange;
}
copyTarget.SetOwnBrain( brain );
if ( Inventory != null && Inventory.AllItems.Count > 0 )
{
GameNpcInventoryTemplate inventoryTemplate = Inventory as GameNpcInventoryTemplate;
if( inventoryTemplate != null )
//.........这里部分代码省略.........
示例14: IsFriend
/// <summary>
/// Whether this NPC is a friend or not.
/// </summary>
/// <param name="npc">The NPC that is checked against.</param>
/// <returns></returns>
public virtual bool IsFriend(GameNPC npc)
{
if (Faction == null || npc.Faction == null)
return false;
return (npc.Faction == Faction || Faction.FriendFactions.Contains(npc.Faction));
}
示例15: GetLoot
/// <summary>
/// Returns the loot for the given Mob
/// </summary>
/// <param name="mob"></param>
/// <param name="killer"></param>
/// <returns></returns>
public static ItemTemplate[] GetLoot(GameNPC mob, GameObject killer)
{
LootList lootList = null;
IList generators = GetLootGenerators(mob);
foreach (ILootGenerator generator in generators)
{
try
{
if (lootList == null)
lootList = generator.GenerateLoot(mob, killer);
else
lootList.AddAll(generator.GenerateLoot(mob, killer));
}
catch (Exception e)
{
if (log.IsErrorEnabled)
log.Error("GetLoot", e);
}
}
if (lootList != null)
return lootList.GetLoot();
else
return new ItemTemplate[0];
}