Exemple #1
0
function send_message($from_id, $to_id, $msg, $type = 0)
{
    $msg = trim($msg);
    $type = restrict_to($type, array(0, 1));
    // 0 = direct, 1 = clan
    if (strlen($msg) > MAX_MSG_LENGTH) {
        throw new Exception('The message was longer than the maximum message length of ' . MAX_MSG_LENGTH . ' characters.');
    }
    $prevMsg = query_item("SELECT message FROM messages WHERE send_from = :from AND send_to = :to ORDER BY date DESC LIMIT 1", array(':from' => $from_id, ':to' => $to_id));
    if ($prevMsg != $msg) {
        query("INSERT INTO messages (message_id, send_from, send_to, message, type, date) VALUES (default, :from, :to, :message, :type, now())", array(':from' => $from_id, ':to' => $to_id, ':message' => $msg, ':type' => $type));
        return true;
    } else {
        return false;
    }
}
 public function testRestrictToDefault()
 {
     $this->assertEquals('grace', restrict_to('bob', ['joe', 'john', 'jake'], 'grace'));
 }
Exemple #3
0
 $random_encounter = rand(1, 400) == 1;
 $combat_data = array();
 $char_id = self_char_id();
 $player = new Player($char_id);
 $error_template = 'npc.no-one.tpl';
 // Error template also used down below.
 $npc_template = $error_template;
 // Error condition by default.
 $turns = $player->turns();
 $is_villager = false;
 $ninja_str = $player->getStrength();
 $ninja_health = $player->vo->health;
 $static_npcs = array('peasant', 'thief', 'merchant', 'guard', 'samurai');
 $npcs = NpcFactory::npcsData();
 $possible_npcs = array_merge($static_npcs, array_keys($npcs));
 $victim = restrict_to($victim, $possible_npcs);
 // Filter to only the correct options.
 if ($turns > 0 && !empty($victim)) {
     // Strip stealth when attacking samurai or oni
     if ($player->hasStatus('stealth') && (strtolower($victim) == 'samurai' || strtolower($victim) == 'oni')) {
         $player->subtractStatus(STEALTH);
     }
     $attacker_str = $player->getStrength();
     $attacker_health = $player->vo->health;
     $attacker_gold = $player->vo->gold;
     // Perform a random encounter (currently only oni).
     if ($random_encounter) {
         // *** ONI, M********a! ***
         // **********************************************************
         // *** Oni attack! Yay!                                   ***
         // *** They take turns and a kill and do a little damage. ***
Exemple #4
0
 // naive spam detection attempt
 $message = in('message', null, null);
 // Unfiltered input for this message.
 $target_id = (int) in('target_id') ? (int) in('target_id') : ($to ? get_user_id($to) : null);
 // Id takes precedence
 $ninja = new Player(self_char_id());
 $clan = ClanFactory::clanOfMember($ninja);
 $has_clan = $clan ? true : false;
 $page = in('page', 1, 'non_negative_int');
 $limit = 25;
 $offset = non_negative_int(($page - 1) * $limit);
 $delete = in('delete');
 $informational = in('informational');
 $type = in('type');
 // Clan chat or normal messages.
 $type = restrict_to($type, array(0, 1));
 $message_sent_to = null;
 // Names or name to display.
 $message_to = null;
 // strings clan or individual if sent to those respectively.
 if ($target_id) {
     $to = get_char_name($target_id);
 }
 set_setting('last_messaged', $to);
 switch (true) {
     case $command == 'clan' && $_POST:
         $messages_type = 'clan';
         $current_tab = 'clan';
         $type = 1;
         break;
     case $command == 'clan':
 /**
  * Attack a specific npc
  *
  * @todo remove REQUEST_URI access and use params
  * @see http://nw.local/npc/attack/villager
  * @see http://nw.local/npc/attack/guard/
  */
 public function attack()
 {
     // This used to pull directly from $victim get param
     $url_part = $_SERVER['REQUEST_URI'];
     if (preg_match('#\\/(\\w+)(\\/)?$#', $url_part, $matches)) {
         $victim = $matches[1];
     } else {
         $victim = null;
         // No match, victim is null.
     }
     $today = date("F j, Y, g:i a");
     // Today var is only used for creating mails.
     $turn_cost = 1;
     $health = true;
     $combat_data = [];
     $player = Player::find(self_char_id());
     $error_template = 'npc.no-one.tpl';
     // Error template also used down below.
     $npc_template = $error_template;
     // Error condition by default.
     $npcs = NpcFactory::npcsData();
     $possible_npcs = array_merge(self::$STATIC_NPCS, array_keys($npcs));
     $victim = restrict_to($victim, $possible_npcs);
     // Filter to only the correct options.
     $standard_npcs = ['peasant' => 'attackVillager', 'merchant' => 'attackMerchant', 'guard' => 'attackGuard'];
     $method = null;
     if ($player && $player->turns() > 0 && !empty($victim)) {
         // Strip stealth when attacking special NPCs
         if ($player->hasStatus('stealth') && in_array(strtolower($victim), self::$STEALTH_REMOVING_NPCS)) {
             $player->subtractStatus(STEALTH);
         }
         if ($this->startRandomEncounter()) {
             $method = 'randomEncounter';
         } elseif (array_key_exists($victim, $npcs)) {
             list($npc_template, $combat_data) = $this->attackAbstractNpc($victim, $player, $npcs);
         } else {
             if (array_key_exists($victim, $standard_npcs)) {
                 $method = $standard_npcs[$victim];
             } else {
                 if ($victim == "samurai") {
                     if ($player->level < 2 || $player->kills < 1) {
                         $turn_cost = 0;
                         $weakness_error = 'You are too weak to attack the samurai.';
                         $npc_template = 'npc.samurai.tpl';
                     } else {
                         $method = 'attackSamurai';
                     }
                 } else {
                     if ($victim == 'thief') {
                         // Check the counter to see whether they've attacked a thief multiple times in a row.
                         $counter = $this->getThiefCounter();
                         $this->setThiefCounter($counter + 1);
                         // Incremement the current state of the counter.
                         if ($counter > 20 && rand(1, 3) == 3) {
                             // Only after many attacks do you have the chance to be attacked back by the group of thieves.
                             $this->setThiefCounter(0);
                             // Reset the counter to zero.
                             $method = 'attackGroupOfThieves';
                         } else {
                             $method = 'attackNormalThief';
                         }
                     }
                 }
             }
         }
         if (is_callable([$this, $method], false)) {
             list($npc_template, $combat_data) = $this->{$method}($player);
         }
         if ($player->health() <= 0) {
             // FINAL CHECK FOR DEATH
             $player->death();
             $health = false;
             sendMessage("SysMsg", $player->name(), "DEATH: You have been killed by a {$victim} on {$today}");
         }
         // Subtract the turn cost for attacking an npc
         // almost always 1 apart from perhaps oni or group-of-thieves
         $player->subtractTurns($turn_cost);
         $player->save();
     }
     // Uses a sub-template inside for specific npcs.
     $parts = ['victim' => $victim, 'npc_template' => $npc_template, 'attacked' => 1, 'turns' => $player ? $player->turns() : null, 'health' => $health];
     return ['template' => 'npc.tpl', 'title' => 'Battle', 'parts' => $parts + $combat_data, 'options' => ['quickstat' => 'player']];
 }