Example #1
0
 public static function execute(SR_Player $player, array $args)
 {
     # Syntax
     if (count($args) !== 2) {
         self::reply($player, Shadowhelp::getHelp($player, 'gmul'));
         return false;
     }
     # Args
     if (false === ($target = Shadowrun4::getPlayerByShortName($args[0]))) {
         self::rply($player, '1017');
         return false;
     } elseif ($target === -1) {
         self::rply($player, '1018');
         return false;
     }
     # Valid cost?
     $field = $args[1];
     if (false === ($cost = Shadowcmd_lvlup::getKarmaCostFactor($field))) {
         self::rply($player, '1024');
         return false;
     }
     # Gather data
     if (false !== ($spell = $target->getSpell($field))) {
         $have_level = $target->getSpellBaseLevel($field);
         $is_spell = true;
     } else {
         $have_level = $target->getBase($field);
         $is_spell = false;
     }
     $karma_back = $cost * $have_level;
     # Limit
     if ($have_level <= 0) {
         self::reply($player, 'Lowered to 0 already!');
         return false;
     }
     # Apply
     if ($is_spell === true) {
         $target->levelupSpell($field, -1);
     } else {
         $target->increaseField($field, -1);
     }
     $target->increaseField('karma', $karma_back);
     $target->modify();
     # Announce
     return self::reply($player, sprintf('%s reverted %s back to level %s and got %s karma back.', $target->getName(), $field, $have_level - 1, $karma_back));
 }
Example #2
0
 public function levelupFieldTo($field, $value)
 {
     $value = (int) $value;
     $old = $this->getBase($field);
     $by = $value - $old;
     if (false === $this->saveBase($field, $value)) {
         return false;
     }
     $this->modify();
     return $this->msg('5285', array(Shadowfunc::translateVariable($this, $field), $value, $by, Shadowcmd_lvlup::getMaxLevel($this, $field), Shadowcmd_lvlup::getKarmaCost($field, $value)));
 }
Example #3
0
 private function onSurgeryB(SR_Player $player, $field)
 {
     echo "Got {$field}\n";
     $field = Shadowfunc::unshortcutVariable($player, $field);
     # rü => armor
     echo "Got {$field}\n";
     $field = Shadowfunc::untranslateVariable($player, $field);
     # rüstung => armor
     echo "Got {$field}\n";
     if ($field === 'essence') {
         $player->msg('1176', array($field));
         # You cannot do surgery on your %s.
         return false;
     }
     if (true === in_array($field, SR_Player::$ATTRIBUTE)) {
         $price = $this->getAttributePrice($field);
         $section = 'attribute';
     } elseif (true === in_array($field, SR_Player::$SKILL)) {
         $price = $this->getSkillPrice($field);
         $section = 'skill';
     } elseif (Shadowfunc::isSpell($field)) {
         if ($player->getSpellBaseLevel($field) === -1) {
             $player->msg('1048');
             # You don't have this spell.
             return false;
         }
         $price = $this->getSpellPrice($field);
         $section = 'spell';
     } elseif (true === in_array($field, SR_Player::$KNOWLEDGE)) {
         $price = $this->getKnowledgePrice($field);
         $section = 'knowledge';
     } elseif ($field === 'male' || $field === 'female') {
         $price = $this->getGenderPrice($field);
         $section = 'gender';
     } elseif (true === in_array($field, array_keys(SR_Player::$RACE))) {
         $price = $this->getRacePrice($field);
         $section = 'race';
     } else {
         $player->msg('1176', array($field));
         # You cannot do surgery on your %s.
         return false;
     }
     if ($price === false) {
         $player->msg('1176', array($field));
         # You cannot do surgery on your %s.
         return false;
     }
     $dprice = Shadowfunc::displayNuyen($price);
     if ($price > $player->getNuyen()) {
         $player->msg('1063', array($dprice, $player->displayNuyen()));
         return false;
     }
     if (false === ($cost = Shadowcmd_lvlup::getKarmaCostFactor($field))) {
         // 			$player->message('Database error 1!');
         // 			return false;
     }
     $karma_back = 0;
     switch ($section) {
         case 'skill':
         case 'knowledge':
         case 'attribute':
             if ($cost === false) {
                 $player->message('Database error 2.2!');
                 return false;
             }
             # Get the minimum base
             if (0 > ($racebase = $player->getRaceBaseVar($field, -1))) {
                 $racebase = 0;
                 // 					$player->message('Database error 2!');
                 // 					return false;
             }
             # Get current base
             if (false === ($current = $player->getBase($field))) {
                 $player->message('Database error 3!');
                 return false;
             }
             # Reached min?
             if ($current <= $racebase) {
                 $player->msg('1177', array($field, $racebase));
                 return false;
             }
             $karma_back = $cost * $current;
             if (false === $player->increaseField($field, -1)) {
                 $player->message('Database error 5!');
                 return false;
             }
             $current--;
             break;
         case 'spell':
             if ($cost === false) {
                 $player->message('Database error 2.2!');
                 return false;
             }
             # Get current base
             if (-1 === ($current = $player->getSpellBaseLevel($field))) {
                 $player->message('Database error 3!');
                 return false;
             }
             # Reached min?
             if ($current <= 0) {
                 $player->msg('1177', array($field, $racebase));
                 return false;
             }
             $karma_back = $cost * $current;
             if (false === $player->levelupSpell($field, -1)) {
                 $player->message('Database error 7-1!');
                 return false;
             }
             $current--;
             break;
         case 'gender':
             if (false === $player->saveBase($section, $field)) {
                 $player->message('Database error 6.1!');
             }
             $current = $field;
             break;
         case 'race':
             $player->message('Database Error 0.8.15');
             return false;
         default:
             $player->msg('1176', array($field));
             return false;
     }
     if (false === $player->pay($price)) {
         $player->message('Database error 0.1!');
         return false;
     }
     if (false === $player->increaseField('karma', $karma_back)) {
         $player->message('Database error 0.2!');
         return false;
     }
     // 		if (false === $player->alterField($field, $by))
     // 		{
     // 			$player->message('Database error 0.1!');
     // 			return false;
     // 		}
     $player->modify();
     $essence_lost = 0;
     return $player->msg('5263', array($dprice, $field, $current, $essence_lost, $karma_back));
     # You paid %s and got your %s changed to %s. You lost %s essence while getting %s karma back.
 }