Просмотр файла game/2/f_additem.dat

Размер файла: 7.31Kb
  1. <?php
  2. global $g_destroy, $l_i;
  3.  
  4. if ($count!='count') {
  5. $count=intval($count);
  6. if (gettype($count)!='integer' || $count==0) {msg('Количество равно '.$count); if ($journal && $to) addjournal($loc,$to,'Количество равно '.$count); $res=0; return 0;}
  7. }
  8. if ($time_delete==-1) $time_delete=$g_destroy;
  9. if (strpos($item,'_')!==false) $tk=substr($item,0,strpos($item,'_')); else
  10. if (strpos($item,'-')!==false) $tk=substr($item,0,strpos($item,'-')); else $tk=$item;
  11. if (substr($item,0,5)=='i.rr.') $title_v=explode('|','руна|50'); else if (!file_exists('items/'.$tk)) {$res=0; return 0;} else {$title_v=explode('|',implode('',file('items/'.$tk)));}
  12. $title_v=$title_v[0];
  13. if ($from && $from!='loc' && !isset($l_i[$loc][$from])) {if ($journal && $to) addjournal($loc,$to,'Не от кого забрать '.$title_v); $res=0; return 0;}
  14. if ($to && $to!='loc' && !isset($l_i[$loc][$to])) {if ($journal && $from) addjournal($loc,$from,'Некому передать '.$title_v); $res=0; return 0;}
  15.  
  16. // получение кол-ва
  17. if ($count=='count') {
  18. if ($from=='loc') {
  19. if (!isset($l_i[$loc][$item])) {$res=0; return 0;} else {$tmp=explode('|',$l_i[$loc][$item]); $res=$tmp[1]; return $tmp[1];}
  20. } else {$res=intval(preg_replace('/.*'.$item.':(\d+).*/','\\1',$l_i[$loc][$from][$ft])); return $res;}
  21. }
  22.  
  23. if ($item=='i.q.pjpt' || $item=='i.q.pdeath') if (substr($to,0,2)=='u.' && (strpos($l_i[$loc][$to][$tt],$item)!==false || $count>1)) msg('У вас уже есть '.$title_v.', нельзя хранить более одного');
  24. if ($item=='i.q.ssword' && substr($to,0,2)=='u.') {$tcs=intval(preg_replace('/.*'.$item.':(\d+).*/','\\1',$l_i[$loc][$to][$tt])); if ($tcs>1 || $count>2 || $tcs==1 && $count==2) msg('Можно держать одновременно не более 2 стеклянных мечей');}
  25. if ($to==$from && ($ft=='bank' || $tt=='bank') && substr($to,0,2)=='u.' && strlen($l_i[$loc][$to][$tt])>800 && strpos($l_i[$loc][$to][$tt],$item.':')===false) msg('Нет места для '.$title_v);
  26. if (substr($item,0,4)=='i.s.' && (substr($to,0,2)=='u.' || substr($from,0,2)=='u.')) msg('Нельзя передать');
  27.  
  28. if ($from) {
  29. if ($from=='loc') {
  30. if (!isset($l_i[$loc][$item])) {
  31. if ($journal && $to) addjournal($loc,$to,$title_v.' отсутствует');
  32. $res=0;
  33. return 0;
  34. } else {
  35. $tmp=explode('|',$l_i[$loc][$item]);
  36. if ($tmp[1]<$count) {if ($journal && $to) addjournal($loc,$to,'Количество '.$title_v.' меньше, чем '.$count); $res=0; return 0;}
  37. $tmp[1]-=$count;
  38. if ($tmp[1]==0) unset($l_i[$loc][$item]); else $l_i[$loc][$item]=implode('|',$tmp);
  39. }
  40. }
  41.  
  42. if ($from!='loc') {
  43. if (substr($from,0,6)=='i.s.d.') $d=1; else $d=0;
  44. if (!$d) {
  45. $ftitle_v=explode('|',$l_i[$loc][$from]['char']);
  46. $ftitle_v=$ftitle_v[0];
  47. $items=$l_i[$loc][$from][$ft];
  48. } else {$tdied=explode('|',$l_i[$loc][$from]); $items=str_replace(',','|',$tdied[3]);}
  49. $items=preg_replace ('/\|{2,}/','|',$items);
  50. if(substr($items,0,1)=='|') $items=substr($items,1);
  51. if(substr($items,strlen($items)-1,1)=='|') $items=substr($items,0,strlen($items)-1);
  52.  
  53. $tcount=intval(preg_replace('/.*'.$item.':(\d+).*/','\\1',$items));
  54. if ($tcount==0) {
  55. if ($msg) msg('У вас нет '.$title_v);
  56. if ($journal && $to) addjournal($loc,$to,'Количество '.$title_v.' равно нулю');
  57. if ($journal && !$d) addjournal($loc,$from,'У вас нет '.$title_v);
  58. $res=0;
  59. return 0;
  60. } else {
  61. if ($tcount<$count) {
  62. if ($msg) msg('У вас недостаточно '.$title_v.' (надо '.$count.')');
  63. if ($journal && $to) addjournal($loc,$to,'Количество '.$title_v.' меньше, чем '.$count);
  64. if ($journal && !$d) addjournal($loc,$from,'У вас количество '.$title_v.' меньше, чем '.$count);
  65. $res=0;
  66. return 0;
  67. }
  68. if ($tcount==$count && strpos($items,'='.$item.':'.$tcount)===false) { // удаляем предмет (кроме торговцев, у кот. ver|min|max=id:count), проверяем equip
  69. $items=preg_replace('/\|?'.$item.':(\d+)/','',$items);
  70. $equip=$l_i[$loc][$from]['equip'];
  71. $tbp=strpos($l_i[$loc][$from]['equip'],$item);
  72. if ($tbp===false) $tb='a'; else $tb=$l_i[$loc][$from]['equip']{$tbp+strlen($item)};
  73. if (!$d && $equip && ($tb=='|' || $tb=='')) {
  74. $equip=preg_replace('/'.$item.'\|?/','',$equip);
  75. $equip=preg_replace ('/\|{2,}/','|',$equip);
  76. if(substr($equip,0,1)=='|') $equip=substr($equip,1);
  77. if(substr($equip,strlen($equip)-1,1)=='|') $equip=substr($equip,0,strlen($equip)-1);
  78. $l_i[$loc][$from]['equip']=$equip;
  79. $l_i[$loc][$from][$ft]=$items;
  80. calcparam($loc,$from);
  81. }
  82. }else{
  83. $tcount-=$count;
  84. $items=preg_replace('/'.$item.':(\d+)/',$item.':'.$tcount,$items);
  85. }
  86. if (!$d) $l_i[$loc][$from][$ft]=$items; else {if (strpos($tdied[0],'*')===false) $clan=''; else $clan=substr($tdied[0],strpos($tdied[0],'*')+1,strrpos($tdied[0],'*')-strpos($tdied[0],'*')-1); if ($to) $tc=explode('|',$l_i[$loc][$to]['char']); else $tc[0]=''; if (strpos($tc[0],'*')===false) $clan1=''; else $clan1=substr($tc[0],strpos($tc[0],'*')+1,strrpos($tc[0],'*')-strpos($tc[0],'*')-1); if($tc[13]) $wife=substr($from,6,strrpos($from,'.')-6)==substr($tc[13],0,strlen(substr($from,6,strrpos($from,'.')-6))); else $wife=0; if (!$tdied[1] && $to && substr($from,0,strlen('i.s.d.'.$to))!='i.s.d.'.$to && (!$clan1 || ($clan1 && $clan1!=$clan)) && !$wife && substr($from,0,11)!='i.s.d.u.qv.') docrim($loc,$to,'мародер'); $tdied[3]=str_replace('|',',',$items); $l_i[$loc][$from]=implode('|',$tdied);}
  87. if ($journal && $to=='loc') {if ($journal && !$d) addjournal($loc,$from,'Вы бросили '.$count.' '.$title_v); if ($journal && !$d) addjournal($loc,'all',$ftitle_v. ' бросил '.$count.' '.$title_v,$from);}
  88. if ($journal && $to!='loc') if ($journal && !$d) addjournal($loc,$from,'Вы потеряли '.$count.' '.$title_v);
  89. }
  90. }
  91. }
  92.  
  93.  
  94. if ($to) {
  95.  
  96. if ($to!='loc') {
  97. if (substr($to,0,6)=='i.s.d.') $d=1; else $d=0;
  98. if (!$d) {
  99. $ftitle_v=explode('|',$l_i[$loc][$to]['char']);
  100. $ftitle_v=$ftitle_v[0];
  101. $items=$l_i[$loc][$to][$tt];
  102. } else {$tdied=explode('|',$l_i[$loc][$to]); $items=str_replace(',','|',$tdied[3]);}
  103.  
  104. $items=preg_replace ('/\|{2,}/','|',$items);
  105. if(substr($items,0,1)=='|') $items=substr($items,1);
  106. if(substr($items,strlen($items)-1,1)=='|') $items=substr($items,0,strlen($items)-1);
  107.  
  108. if (substr($to,0,2)=='u.') {
  109. if (strlen($items)>800 && strpos($items,$item.':')===false) {
  110. addjournal($loc,$to,'Не хватает места, '.$title_v.' упал вам под ноги');
  111. $to='loc';
  112. }
  113. }
  114.  
  115. if ($to!='loc') {
  116. $tcount=intval(preg_replace('/.*'.$item.':(\d+).*/','\\1',$items));
  117.  
  118. if ($tcount==0) { // торговцам новый предмет в банк не добавляем
  119. if (strpos($items,'='.$item.':'.$tcount)===false) if($items=='') $items=$item.':'.$count; else $items.='|'.$item.':'.$count;
  120. } else {
  121. $tcount+=$count;
  122. $items=preg_replace('/'.$item.':(\d+)/',$item.':'.$tcount,$items);
  123. }
  124. if (!$d) $l_i[$loc][$to][$tt]=$items; else {$tdied[3]=str_replace('|',',',$items); $l_i[$loc][$to]=implode('|',$tdied);}
  125. if ($journal && $from=='loc') {if ($journal && !$d) addjournal($loc,$to,'Вы подняли '.$count.' '.$title_v); if ($journal && !$d) addjournal($loc,'all',$ftitle_v. ' поднял '.$count.' '.$title_v,$to);}
  126. if ($journal && $from!='loc') if ($journal && !$d) addjournal($loc,$to,'Вы получили '.$count.' '.$title_v);
  127. }
  128. }
  129.  
  130. if ($to=='loc') {
  131. if (!isset($l_i[$loc][$item])) {
  132. $l_i[$loc][$item]=$title_v.'|'.$count.'|'.(time()+$time_delete);
  133. } else {
  134. $tmp=explode('|',$l_i[$loc][$item]);
  135. $tmp[1]+=$count;
  136. $tmp[2]=time()+$time_delete;
  137. $l_i[$loc][$item]=implode('|',$tmp);
  138. }
  139. }
  140. }
  141. $res=1;
  142. return 1; // ок