- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
此创建的对象有 13 个单独的字符串条目。
在当前配置中,它会生成 3 个独立的生成对象,每个对象都有一个字符串。我需要使一件元素生成至少有八个单独的刺痛条目。
namespace Server
{
public class GenItems
{
private static int m_Count;
private const int ICount = 8;
private const int HomeRange = 20;
private const bool TotalRespawn = false;
public static void Initialize()
{
CommandSystem.Register("GenItems", AccessLevel.Administrator, new CommandEventHandler(Generate_OnCommand));
}
[Usage("GenItems")]
[Description("Generates Items")]
private static void Generate_OnCommand(CommandEventArgs e)
{
Parse(e.Mobile);
}
public static void Parse(Mobile from)
{
from.SendMessage("Generating all items...");
MakeSpawner(new string[] { "aaa", "bbb", "ccc" }, 2850, 810, 0);
}
private static Queue m_ToDelete = new Queue();
public static void ClearSpawners(int x, int y, int z)
{
IPooledEnumerable eable = Map.Sample.GetItemsInRange(new Point3D(x, y, z), 0);
foreach (Item item in eable)
{
if (item is Spawner && item.Z == z)
m_ToDelete.Enqueue(item);
}
eable.Free();
while (m_ToDelete.Count > 0)
((Item)m_ToDelete.Dequeue()).Delete();
}
private static void MakeSpawner(string[] types, int x, int y, int z)
{
if (types.Length == 0)
return;
ClearSpawners(x, y, z);
for (int i = 0; i < types.Length; ++i)
{
Spawner sp = new Spawner(types[i]);
sp.Count = ICount;
sp.HomeRange = HomeRange;
sp.MoveToWorld(new Point3D(x, y, z), Map.Sample);
if (TotalRespawn)
{
sp.Respawn();
sp.BringToHome();
}
++m_Count;
}
}
}
}
因为我还是一个学习 C# 的新手,所以我没有想法。
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using Server;
using Server.Items;
namespace Server.Mobiles
{
public class Spawner : Item
{
private int m_Team;
private int m_HomeRange;
private int m_WalkingRange = -1;
private int m_Count;
private TimeSpan m_MinDelay;
private TimeSpan m_MaxDelay;
private List<string> m_CreaturesName;
private List<IEntity> m_Creatures;
private DateTime m_End;
private InternalTimer m_Timer;
private bool m_Running;
private bool m_Group;
private WayPoint m_WayPoint;
public bool IsFull{ get{ return ( m_Creatures != null && m_Creatures.Count >= m_Count ); } }
public List<string> CreaturesName
{
get { return m_CreaturesName; }
set
{
m_CreaturesName = value;
if ( m_CreaturesName.Count < 1 )
Stop();
InvalidateProperties();
}
}
public override void OnAfterDuped( Item newItem )
{
Spawner s = newItem as Spawner;
if ( s == null )
return;
s.m_CreaturesName = new List<string>( m_CreaturesName );
}
[CommandProperty( AccessLevel.GameMaster )]
public int Count
{
get { return m_Count; }
set { m_Count = value; InvalidateProperties(); }
}
[CommandProperty( AccessLevel.GameMaster )]
public WayPoint WayPoint
{
get
{
return m_WayPoint;
}
set
{
m_WayPoint = value;
}
}
[CommandProperty( AccessLevel.GameMaster )]
public bool Running
{
get { return m_Running; }
set
{
if ( value )
Start();
else
Stop();
InvalidateProperties();
}
}
[CommandProperty( AccessLevel.GameMaster )]
public int HomeRange
{
get { return m_HomeRange; }
set { m_HomeRange = value; InvalidateProperties(); }
}
[CommandProperty( AccessLevel.GameMaster )]
public int WalkingRange
{
get { return m_WalkingRange; }
set { m_WalkingRange = value; InvalidateProperties(); }
}
[CommandProperty( AccessLevel.GameMaster )]
public int Team
{
get { return m_Team; }
set { m_Team = value; InvalidateProperties(); }
}
[CommandProperty( AccessLevel.GameMaster )]
public TimeSpan MinDelay
{
get { return m_MinDelay; }
set { m_MinDelay = value; InvalidateProperties(); }
}
[CommandProperty( AccessLevel.GameMaster )]
public TimeSpan MaxDelay
{
get { return m_MaxDelay; }
set { m_MaxDelay = value; InvalidateProperties(); }
}
[CommandProperty( AccessLevel.GameMaster )]
public TimeSpan NextSpawn
{
get
{
if ( m_Running )
return m_End - DateTime.Now;
else
return TimeSpan.FromSeconds( 0 );
}
set
{
Start();
DoTimer( value );
}
}
[CommandProperty( AccessLevel.GameMaster )]
public bool Group
{
get { return m_Group; }
set { m_Group = value; InvalidateProperties(); }
}
[Constructable]
public Spawner( int amount, int minDelay, int maxDelay, int team, int homeRange, string creatureName ) : base( 0x1f13 )
{
List<string> creaturesName = new List<string>();
creaturesName.Add( creatureName.ToLower() );
InitSpawn( amount, TimeSpan.FromMinutes( minDelay ), TimeSpan.FromMinutes( maxDelay ), team, homeRange, creaturesName );
}
[Constructable]
public Spawner( string creatureName ) : base( 0x1f13 )
{
List<string> creaturesName = new List<string>();
creaturesName.Add( creatureName.ToLower() );
InitSpawn( 1, TimeSpan.FromMinutes( 5 ), TimeSpan.FromMinutes( 10 ), 0, 4, creaturesName );
}
[Constructable]
public Spawner() : base( 0x1f13 )
{
List<string> creaturesName = new List<string>();
InitSpawn( 1, TimeSpan.FromMinutes( 5 ), TimeSpan.FromMinutes( 10 ), 0, 4, creaturesName );
}
public Spawner( int amount, TimeSpan minDelay, TimeSpan maxDelay, int team, int homeRange, List<string> creaturesName )
: base( 0x1f13 )
{
InitSpawn( amount, minDelay, maxDelay, team, homeRange, creaturesName );
}
public override string DefaultName
{
get { return "Spawner"; }
}
public void InitSpawn( int amount, TimeSpan minDelay, TimeSpan maxDelay, int team, int homeRange, List<string> creaturesName )
{
Visible = false;
Movable = false;
m_Running = true;
m_Group = false;
m_MinDelay = minDelay;
m_MaxDelay = maxDelay;
m_Count = amount;
m_Team = team;
m_HomeRange = homeRange;
m_CreaturesName = creaturesName;
m_Creatures = new List<IEntity>();
DoTimer( TimeSpan.FromSeconds( 1 ) );
}
public Spawner( Serial serial ) : base( serial )
{
}
public override void OnDoubleClick( Mobile from )
{
if ( from.AccessLevel < AccessLevel.GameMaster )
return;
SpawnerGump g = new SpawnerGump( this );
from.SendGump( g );
}
public override void GetProperties( ObjectPropertyList list )
{
base.GetProperties( list );
if ( m_Running )
{
list.Add( 1060742 ); // active
list.Add( 1060656, m_Count.ToString() ); // amount to make: ~1_val~
list.Add( 1061169, m_HomeRange.ToString() ); // range ~1_val~
list.Add( 1060658, "walking range\t{0}", m_WalkingRange ); // ~1_val~: ~2_val~
list.Add( 1060659, "group\t{0}", m_Group ); // ~1_val~: ~2_val~
list.Add( 1060660, "team\t{0}", m_Team ); // ~1_val~: ~2_val~
list.Add( 1060661, "speed\t{0} to {1}", m_MinDelay, m_MaxDelay ); // ~1_val~: ~2_val~
for ( int i = 0; i < 2 && i < m_CreaturesName.Count; ++i )
list.Add( 1060662 + i, "{0}\t{1}", m_CreaturesName[i], CountCreatures( m_CreaturesName[i] ) );
}
else
{
list.Add( 1060743 ); // inactive
}
}
public override void OnSingleClick( Mobile from )
{
base.OnSingleClick( from );
if ( m_Running )
LabelTo( from, "[Running]" );
else
LabelTo( from, "[Off]" );
}
public void Start()
{
if ( !m_Running )
{
if ( m_CreaturesName.Count > 0 )
{
m_Running = true;
DoTimer();
}
}
}
public void Stop()
{
if ( m_Running )
{
m_Timer.Stop();
m_Running = false;
}
}
public void Defrag()
{
bool removed = false;
for ( int i = 0; i < m_Creatures.Count; ++i )
{
IEntity e = m_Creatures[i];
if ( e is Item )
{
Item item = (Item)e;
if ( item.Deleted || item.Parent != null )
{
m_Creatures.RemoveAt( i );
--i;
removed = true;
}
}
else if ( e is Mobile )
{
Mobile m = (Mobile)e;
if ( m.Deleted )
{
m_Creatures.RemoveAt( i );
--i;
removed = true;
}
else if ( m is BaseCreature )
{
BaseCreature bc = (BaseCreature)m;
if ( bc.Controlled || bc.IsStabled )
{
m_Creatures.RemoveAt( i );
--i;
removed = true;
}
}
}
else
{
m_Creatures.RemoveAt( i );
--i;
removed = true;
}
}
if ( removed )
InvalidateProperties();
}
public void OnTick()
{
DoTimer();
if ( m_Group )
{
Defrag();
if ( m_Creatures.Count == 0 )
{
Respawn();
}
else
{
return;
}
}
else
{
Spawn();
}
}
public void Respawn()
{
RemoveCreatures();
for ( int i = 0; i < m_Count; i++ )
Spawn();
}
public void Spawn()
{
if ( m_CreaturesName.Count > 0 )
Spawn( Utility.Random( m_CreaturesName.Count ) );
}
public void Spawn( string creatureName )
{
for ( int i = 0; i < m_CreaturesName.Count; i++ )
{
if ( m_CreaturesName[i] == creatureName )
{
Spawn( i );
break;
}
}
}
public void Spawn( int index )
{
Map map = Map;
if ( map == null || map == Map.Internal || m_CreaturesName.Count == 0 || index >= m_CreaturesName.Count || Parent != null )
return;
Defrag();
if ( m_Creatures.Count >= m_Count )
return;
Type type = SpawnerType.GetType( m_CreaturesName[index] );
if ( type != null )
{
try
{
object o = Activator.CreateInstance( type );
if ( o is Mobile )
{
Mobile m = (Mobile)o;
m_Creatures.Add( m );
Point3D loc = ( m is BaseVendor ? this.Location : GetSpawnPosition() );
m.OnBeforeSpawn( loc, map );
InvalidateProperties();
m.MoveToWorld( loc, map );
if ( m is BaseCreature )
{
BaseCreature c = (BaseCreature)m;
if( m_WalkingRange >= 0 )
c.RangeHome = m_WalkingRange;
else
c.RangeHome = m_HomeRange;
c.CurrentWayPoint = m_WayPoint;
if ( m_Team > 0 )
c.Team = m_Team;
c.Home = this.Location;
}
m.OnAfterSpawn();
}
else if ( o is Item )
{
Item item = (Item)o;
m_Creatures.Add( item );
Point3D loc = GetSpawnPosition();
item.OnBeforeSpawn( loc, map );
InvalidateProperties();
item.MoveToWorld( loc, map );
item.OnAfterSpawn();
}
}
catch
{
}
}
}
public Point3D GetSpawnPosition()
{
Map map = Map;
if ( map == null )
return Location;
// Try 10 times to find a Spawnable location.
for ( int i = 0; i < 10; i++ )
{
int x = Location.X + (Utility.Random( (m_HomeRange * 2) + 1 ) - m_HomeRange);
int y = Location.Y + (Utility.Random( (m_HomeRange * 2) + 1 ) - m_HomeRange);
int z = Map.GetAverageZ( x, y );
if ( Map.CanSpawnMobile( new Point2D( x, y ), this.Z ) )
return new Point3D( x, y, this.Z );
else if ( Map.CanSpawnMobile( new Point2D( x, y ), z ) )
return new Point3D( x, y, z );
}
return this.Location;
}
public void DoTimer()
{
if ( !m_Running )
return;
int minSeconds = (int)m_MinDelay.TotalSeconds;
int maxSeconds = (int)m_MaxDelay.TotalSeconds;
TimeSpan delay = TimeSpan.FromSeconds( Utility.RandomMinMax( minSeconds, maxSeconds ) );
DoTimer( delay );
}
public void DoTimer( TimeSpan delay )
{
if ( !m_Running )
return;
m_End = DateTime.Now + delay;
if ( m_Timer != null )
m_Timer.Stop();
m_Timer = new InternalTimer( this, delay );
m_Timer.Start();
}
private class InternalTimer : Timer
{
private Spawner m_Spawner;
public InternalTimer( Spawner spawner, TimeSpan delay ) : base( delay )
{
if ( spawner.IsFull )
Priority = TimerPriority.FiveSeconds;
else
Priority = TimerPriority.OneSecond;
m_Spawner = spawner;
}
protected override void OnTick()
{
if ( m_Spawner != null )
if ( !m_Spawner.Deleted )
m_Spawner.OnTick();
}
}
public int CountCreatures( string creatureName )
{
Defrag();
int count = 0;
for ( int i = 0; i < m_Creatures.Count; ++i )
if ( Insensitive.Equals( creatureName, m_Creatures[i].GetType().Name ) )
++count;
return count;
}
public void RemoveCreatures( string creatureName )
{
Defrag();
for ( int i = 0; i < m_Creatures.Count; ++i )
{
IEntity e = m_Creatures[i];
if ( Insensitive.Equals( creatureName, e.GetType().Name ) )
e.Delete();
}
InvalidateProperties();
}
public void RemoveCreatures()
{
Defrag();
for ( int i = 0; i < m_Creatures.Count; ++i )
m_Creatures[i].Delete();
InvalidateProperties();
}
public void BringToHome()
{
Defrag();
for ( int i = 0; i < m_Creatures.Count; ++i )
{
IEntity e = m_Creatures[i];
if ( e is Mobile )
{
Mobile m = (Mobile)e;
m.MoveToWorld( Location, Map );
}
else if ( e is Item )
{
Item item = (Item)e;
item.MoveToWorld( Location, Map );
}
}
}
public override void OnDelete()
{
base.OnDelete();
RemoveCreatures();
if ( m_Timer != null )
m_Timer.Stop();
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 4 ); // version
writer.Write( m_WalkingRange );
writer.Write( m_WayPoint );
writer.Write( m_Group );
writer.Write( m_MinDelay );
writer.Write( m_MaxDelay );
writer.Write( m_Count );
writer.Write( m_Team );
writer.Write( m_HomeRange );
writer.Write( m_Running );
if ( m_Running )
writer.WriteDeltaTime( m_End );
writer.Write( m_CreaturesName.Count );
for ( int i = 0; i < m_CreaturesName.Count; ++i )
writer.Write( m_CreaturesName[i] );
writer.Write( m_Creatures.Count );
for ( int i = 0; i < m_Creatures.Count; ++i )
{
IEntity e = m_Creatures[i];
if ( e is Item )
writer.Write( (Item)e );
else if ( e is Mobile )
writer.Write( (Mobile)e );
else
writer.Write( Serial.MinusOne );
}
}
private static WarnTimer m_WarnTimer;
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
switch ( version )
{
case 4:
{
m_WalkingRange = reader.ReadInt();
goto case 3;
}
case 3:
case 2:
{
m_WayPoint = reader.ReadItem() as WayPoint;
goto case 1;
}
case 1:
{
m_Group = reader.ReadBool();
goto case 0;
}
case 0:
{
m_MinDelay = reader.ReadTimeSpan();
m_MaxDelay = reader.ReadTimeSpan();
m_Count = reader.ReadInt();
m_Team = reader.ReadInt();
m_HomeRange = reader.ReadInt();
m_Running = reader.ReadBool();
TimeSpan ts = TimeSpan.Zero;
if ( m_Running )
ts = reader.ReadDeltaTime() - DateTime.Now;
int size = reader.ReadInt();
m_CreaturesName = new List<string>( size );
for ( int i = 0; i < size; ++i )
{
string typeName = reader.ReadString();
m_CreaturesName.Add( typeName );
if ( SpawnerType.GetType( typeName ) == null )
{
if ( m_WarnTimer == null )
m_WarnTimer = new WarnTimer();
m_WarnTimer.Add( Location, Map, typeName );
}
}
int count = reader.ReadInt();
m_Creatures = new List<IEntity>( count );
for ( int i = 0; i < count; ++i )
{
IEntity e = World.FindEntity( reader.ReadInt() );
if ( e != null )
m_Creatures.Add( e );
}
if ( m_Running )
DoTimer( ts );
break;
}
}
if ( version < 3 && Weight == 0 )
Weight = -1;
}
private class WarnTimer : Timer
{
private ArrayList m_List;
private class WarnEntry
{
public Point3D m_Point;
public Map m_Map;
public string m_Name;
public WarnEntry( Point3D p, Map map, string name )
{
m_Point = p;
m_Map = map;
m_Name = name;
}
}
public WarnTimer() : base( TimeSpan.FromSeconds( 1.0 ) )
{
m_List = new ArrayList();
Start();
}
public void Add( Point3D p, Map map, string name )
{
m_List.Add( new WarnEntry( p, map, name ) );
}
protected override void OnTick()
{
try
{
Console.WriteLine( "Warning: {0} bad spawns detected, logged: 'badspawn.log'", m_List.Count );
using ( StreamWriter op = new StreamWriter( "badspawn.log", true ) )
{
op.WriteLine( "# Bad spawns : {0}", DateTime.Now );
op.WriteLine( "# Format: X Y Z F Name" );
op.WriteLine();
foreach ( WarnEntry e in m_List )
op.WriteLine( "{0}\t{1}\t{2}\t{3}\t{4}", e.m_Point.X, e.m_Point.Y, e.m_Point.Z, e.m_Map, e.m_Name );
op.WriteLine();
op.WriteLine();
}
}
catch
{
}
}
}
}
}
最佳答案
允许您将多个生物名称传递给 Spawner
,您应该更改 Spawner
的构造函数像这样:
[Constructable]
public Spawner(params string[] creatureName ) : base( 0x1f13 )
{
InitSpawn( 1, TimeSpan.FromMinutes( 5 ), TimeSpan.FromMinutes( 10 ), 0, 4, creaturesName.ToList() );
}
然后修改你的MakeSpawner
像这样的方法:
private static void MakeSpawner(string[] types, int x, int y, int z)
{
if (types.Length == 0)
return;
ClearSpawners(x, y, z);
Spawner sp = new Spawner(types);
sp.Count = ICount;
sp.HomeRange = HomeRange;
sp.MoveToWorld(new Point3D(x, y, z), Map.Sample);
if (TotalRespawn)
{
sp.Respawn();
sp.BringToHome();
}
++m_Count;
}
注:params
修饰符允许您将单个字符串 ( new Spawner("a")
)、多个字符串 ( new Spanwer("a", "b", "c")
) 或字符串数组 ( new Spanwer(types)
) 传递给同一方法。我还稍微修改了您的代码以使用 LINQ ( using System.Linq
) 转换为 List<string>
.
现在,我唯一担心的是 ClearSpawners(x, y, z);
:如果您添加多个具有相同 x、y、z 的独立生成器,它将(大概)清除旧生成器。我猜,因为这些是刷怪笼,所以它可能没问题,而且每个位置只能有一个刷怪箱。
关于c# - 我的问题是关于向对象添加更多字符串条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52231556/
我正在开发一个带选项卡栏的 ios 应用程序。我的栏上有超过 5 个按钮,所以在 iphone 上我有更多的按钮。现在,假设我有这个按钮:Button1 Button2 Button3 Button4
我有一个带有 UITabBarController 的应用,其中有超过五个选项卡。 当我按更多选项卡时,我会转到moreNavigationController,它是一个UINavigationCon
我有一个导航 Controller 。 NAVC->MORE... 按钮,然后在“更多”下有一些额外的 VC。 如果我转到“更多...”下的 VC,然后转到不在“更多...”上的 VC,那么当我返回到
因此,我想出了这种方案,用于在多个线程同时具有读写访问权限的二叉树中旋转时锁定节点,这涉及每次旋转锁定四个节点,这似乎是一个很多吗?我想到了一种比我想出的方法更聪明的方法来减少所需的锁定,但谷歌并没有
所以我已经尝试了所有方法,但我似乎仍然无法将下拉内容与 dropbtn 对齐。我只希望内容始终位于更多菜单下方。 HTML: `
我正在尝试使用 expect 来自动接受在 --more-- 中提示的 EULA。 #!/usr/bin/expect spawn "./greenplum-perfmon-web-4.1.2.0-b
他们如何在下面提供的网站上制作“告诉我更多”效果。我读过 read more/less effect in jQuery,但我发现该站点的有趣之处在于,除非单击该按钮,否则无法滚动页面。 Effect
现在,Kim Stebel helped me understanding如何使用存在类型键入变量,我需要知道如何在继承中使用它们: 以下代码无法编译: class PagingListModel(s
在我的Cygwin中不可用。另一方面,提供了“ less”命令。也许Cygwin的制造商认为“更多”只是多余的。 我对此很好奇。 最佳答案 安装util-linux软件包,您将获得“更多”的信息 ht
基本上,我想知道是否有人有增加 DTU 与分片的经验。 DTU应该线性地提高性能。因此,如果您有 5 个 DTU,而您改为 10 个 DTU,那么(理论上)您应该获得大约两倍的性能。 因此,四个 SQ
我们使用 asp.net mvc、javascript 和 jQuery(托管在本地计算机上)创建了一个应用程序。基本设计是,当用户从一个页面导航到其他页面时,我们通过隐藏和显示 HTML 页面,将所
我想用 RMonad 做一些基本的事情。有没有办法使用“as monad”功能来 有一个身份 rmonad,可以应用 monad 转换器吗? 有诸如 StateT 变压器之类的常见东西吗? 向现有 m
我有一个 char*[] 数组。我需要能够为其分配字符串并再次删除它们,但我不知道: 如何检查一个元素中是否已经有一个字符串,这样我就不会覆盖它,如果它已经被占用,则继续处理下一个元素? 之后如何将其
基本上,我想知道是否有人有增加 DTU 与分片的经验。 DTU应该线性地提高性能。因此,如果您有 5 个 DTU,而您改为 10 个 DTU,那么(理论上)您应该获得大约两倍的性能。 因此,四个 SQ
我有一个程序可以同时吐出标准错误和标准输出,我想在标准错误上少运行寻呼机,但忽略标准输出。我该怎么做? 更新: 就是这样......我不想丢失标准输出......只是让它远离寻呼机 program 2
基本上,当单击具有类 "dropdown" 的链接时,我无法获取“更多...”链接来对下一个跨度的高度进行动画处理。它根本就没有动画。仅当更改为 Less... 链接并且单击 Less... 链接以折
我正在使用 ExtJS,并认为它是一个了不起的框架。但是,它们没有内置的状态图,这使得依赖于状态的应用程序开发非常痛苦。 我最近发现了这个: https://github.com/jakesgordo
我一直在研究数据结构和算法,遗憾的是在C中。我已经单独实现了一个双向链表,它保存整数并且工作正常,但是当节点(或pub)让它正常工作时我遇到了很多麻烦在本例中)保存多个不同类型的值。我可以创建一个列表
编辑拼写错误 你好, 这可能是一个愚蠢的问题,但如果它能帮助我遵循最佳实践,我不在乎:P 假设我想在 System.Data 命名空间...以及 System.Data.SqlClient 命名空间中
使用 bootstrap 3 CSS、font awesome CSS 和最新的 jQuery JS 文件。 我正在使用 javascript 在单击按钮时在另一个内容 div 之上隐藏/显示一个内容
我是一名优秀的程序员,十分优秀!