00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <Utility.h>
00022 #include "SmallSocket.h"
00023 #include "ItemFactory.h"
00024 #include "SmallHandler.h"
00025
00026
00027 SmallHandler::SmallHandler()
00028 :SocketHandler()
00029 ,m_world(*this)
00030 ,m_mob(*this)
00031 ,m_itemf(*this)
00032 {
00033 m_persist.push_back(&m_pf);
00034 }
00035
00036
00037 SmallHandler::~SmallHandler()
00038 {
00039 }
00040
00041
00042 void SmallHandler::Who(SmallSocket *p2)
00043 {
00044 for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end(); it++)
00045 {
00046 Socket *p0 = (*it).second;
00047 SmallSocket *p = dynamic_cast<SmallSocket *>(p0);
00048 if (p)
00049 {
00050 p2 -> Send(p -> GetName() + "\n");
00051 }
00052 }
00053 }
00054
00055
00056 void SmallHandler::SecTick(time_t t)
00057 {
00058 if (random() % 5 == 0)
00059 {
00060 m_itemf.Spawn();
00061 }
00062 else
00063 if (random() % 120 == 0)
00064 {
00065 m_mob.Spawn();
00066 }
00067 else
00068 if (random() % 5 == 0)
00069 {
00070 m_mob.RandomAction();
00071 }
00072 }
00073
00074
00075 void SmallHandler::ShowCell(SmallSocket *p)
00076 {
00077 int x = p -> GetX();
00078 int y = p -> GetY();
00079 std::string name;
00080 bool n,s,e,w;
00081 m_world.GetAt(x,y,name,n,s,e,w);
00082 p -> Send(name + "\n");
00083 m_mob.ShowNamesAt(p,x,y,"Here is ");
00084 m_itemf.ShowNamesAt(p,x,y,"You see ");
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 std::string str = "Exits:&W";
00112 str += n ? " N" : "";
00113 str += s ? " S" : "";
00114 str += e ? " E" : "";
00115 str += w ? " W" : "";
00116 p -> Send( str + "&n\n");
00117 }
00118
00119
00120 void SmallHandler::Event(int x,int y,const std::string& line,SmallSocket *from,bool bAll)
00121 {
00122 for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end(); it++)
00123 {
00124 Socket *p0 = (*it).second;
00125 SmallSocket *p = dynamic_cast<SmallSocket *>(p0);
00126 if (p && p != from)
00127 {
00128 if (bAll || p -> IsAt(x,y))
00129 {
00130 p -> Send("\n" + line);
00131 p -> SendPrompt();
00132 }
00133 }
00134 }
00135 }
00136
00137
00138 void SmallHandler::Load()
00139 {
00140 for (ipersist_v::iterator it = m_persist.begin(); it != m_persist.end(); it++)
00141 {
00142 IPersist *p = *it;
00143 p -> Load();
00144 }
00145 }
00146
00147
00148 void SmallHandler::ShowStatus(SmallSocket *sendto)
00149 {
00150 sendto -> Send("Number of rooms : &R" + Utility::l2string(m_world.NumberOfCells()) + "&n\n");
00151 sendto -> Send("Number of mobs : &G" + Utility::l2string(m_mob.NumberOfMobs()) + "&n\n");
00152 sendto -> Send("Number of items : &B" + Utility::l2string(m_itemf.NumberOfItems()) + "&n\n");
00153 }
00154
00155