Skip to content

Instantly share code, notes, and snippets.

@PEMapModder
Created May 25, 2015 15:52
Show Gist options
  • Select an option

  • Save PEMapModder/519f33cf6c15ca65a943 to your computer and use it in GitHub Desktop.

Select an option

Save PEMapModder/519f33cf6c15ca65a943 to your computer and use it in GitHub Desktop.
LegionPE plugin source code (spleef part only)
<?php
namespace legionpe\games\spleef;
use legionpe\config\Settings;
use pocketmine\inventory\PlayerInventory;
use pocketmine\item\Item;
use pocketmine\item\Snowball;
class SpleefArena{
/** @var SpleefGame */
private $game;
/** @var int */
private $id;
/** @var SpleefArenaConfig */
private $config;
/** @var SpleefSessionData[] */
private $players = [];
/** @var SpleefSessionData[] */
private $specs = [];
/** @var int */
private $ticks;
/** @var bool */
private $state; // playing: true; waiting: false
public function __construct(SpleefGame $game, $id){
$this->game = $game;
$this->config = Settings::spleef_getArenaConfig($this->id = $id, $game->getMain()->getServer());
}
public function reset(){
foreach($this->players as $player){
$this->kick($player, "match ended", false);
}
foreach($this->specs as $spec){
$this->kick($spec, "match ended", false);
}
$this->config->build();
$this->players = [];
$this->specs = [];
$this->state = false;
}
public function startMatch(){
/**
* @var int $i
* @var SpleefSessionData $player
*/
$values = array_values($this->players);
shuffle($values);
foreach(array_values($values) as $i => $player){
$loc = $this->config->playerStartLocs[$i];
$player->getSession()->getPlayer()->teleport($loc, $loc->yaw, -90);
}
$this->state = true;
$this->ticks = $this->config->maxGameTicks;
}
public function join(SpleefSessionData $data){
$data->joinArena($this->id, false);
$this->players[$data->getSession()->getUID()] = $data;
$this->broadcast("{$data->getSession()} joined the match! There are now " . count($this->players) . " players in the arena.");
$data->getSession()->teleport($this->config->playerPrepLoc);
$this->giveTools($data->getSession()->getPlayer()->getInventory(), $data->getSession()->getRank());
Settings::spleef_updateArenaSigns($this);
if(count($this->players) < $this->config->minPlayers){
return;
}
if(count($this->players) === $this->config->minPlayers){
$this->ticks = $this->config->maxWaitTicks;
}
elseif($this->ticks < $this->config->minWaitTicks or count($this->players) === $this->config->getMaxPlayers()){
$this->ticks = $this->config->minWaitTicks;
$this->broadcastTime();
}
}
public function spectate(SpleefSessionData $data){
$data->joinArena($this->id, true);
$this->specs[$data->getSession()->getUID()] = $data;
$this->broadcastSpecs($data->getSession() . " is now spectating the match!");
$data->getSession()->teleport($this->config->spectatorSpawnLoc);
}
public function kick(SpleefSessionData $data, $reason, $checkPlayers = true){
if($data->isSpectating()){
unset($this->specs[$data->getSession()->getUID()]);
}
elseif($checkPlayers){
unset($this->players[$data->getSession()->getUID()]);
if(count($this->players) === 1){
/** @var SpleefSessionData $winner */
$winner = array_values($this->players)[0];
$award = 16 * Settings::coinsFactor($winner->getSession());
$this->broadcast("The match has ended. {$winner->getSession()} won the match and is awarded with $award coins.");
$winner->getSession()->setCoins($coins = $winner->getSession()->getCoins() + $award);
$winner->getSession()->tell("You now have $coins coins.");
$winner->addWin();
$this->game->getDefaultChatChannel()->broadcast("$winner won a match in $this!");
$this->reset();
}
Settings::spleef_updateArenaSigns($this);
}
$data->quitArena();
$data->getSession()->tell("You left {$this->config->name}: $reason.");
$data->getSession()->teleport(Settings::spleef_spawn($this->game->getMain()->getServer()));
}
public function tick(){
if($this->state){ // playing
$this->ticks--;
$this->broadcastTime();
if($this->ticks === 0){
if(($cnt = count($this->players)) > 1){
$this->broadcast("The match has ended. There are no winners.");
$this->broadcastSpecs("The $cnt survivors will share the award of 20 coins.");
$mean = 20 / $cnt;
foreach($this->players as $player){
$get = round($mean * Settings::coinsFactor($player->getSession()), 2);
$player->getSession()->setCoins($coins = $player->getSession()->getCoins() + $get);
$player->getSession()->tell("You are awarded with $get coins. You now have $coins coins.");
$player->addDraw();
}
$this->game->getDefaultChatChannel()->broadcast("Match in $this ended with a draw with $cnt survivors!");
}
$this->reset();
return;
}
foreach($this->players as $player){
if($player->getSession()->getPlayer()->getFloorY() < ($this->config->lowestY - 1)){
$this->kick($player, "you fell out of the arena");
$this->broadcast("{$player->getSession()} has fallen!");
$player->addLoss();
}
if(count($this->players) === 0){
$this->reset();
return; // not sure what will happen. ConcurrentModificationException?
}
}
}
elseif(count($this->players) > 1){
$this->ticks--;
$this->broadcastTime();
if($this->ticks === 0){
$this->broadcast("The match now starts!");
$this->startMatch();
}
}
}
public function broadcast($msg){
$this->broadcastSpecs($msg);
$this->broadcastPlayers($msg);
}
public function broadcastSpecs($msg){
foreach($this->specs as $spec){
$spec->getSession()->tell($msg);
}
}
public function broadcastPlayers($msg){
foreach($this->players as $player){
$player->getSession()->tell($msg);
}
}
public function broadcastTime(){
if($this->state){
if($this->ticks === 100 or $this->ticks === 200 or $this->ticks === 300 or $this->ticks === 400 or $this->ticks === 600 or $this->ticks === 1200){
$this->broadcast(sprintf("%d seconds left!", $this->ticks / 20));
}
}
elseif($this->ticks === 100 or $this->ticks === 200 or $this->ticks === 300 or $this->ticks === 400 or $this->ticks === 600){
$this->broadcast(sprintf("%d seconds before the match starts!", $this->ticks / 20));
}
}
public function isPlaying(){
return $this->state;
}
public function countPlayers(){
return count($this->players);
}
public function getPlayers(){
return $this->players;
}
public function getSpectators(){
return $this->specs;
}
public function isFull(){
return count($this->players) >= $this->config->getMaxPlayers();
}
public function getGame(){
return $this->game;
}
public function getId(){
return $this->id;
}
public function getConfig(){
return $this->config;
}
public function __toString(){
return $this->config->name;
}
private function giveTools(PlayerInventory $inv, /** @noinspection PhpUnusedParameterInspection */ $rank){
$inv->getHolder()->setHealth(20);
$inv->remove(Item::get(Item::SNOWBALL));
$inv->addItem(...$this->config->playerItems/*[($rank & 0b1100) >> 2]*/); // TODO support shops
$inv->addItem(new Snowball(0, Settings::easter_getSnowballCount($rank)));
}
}
<?php
namespace legionpe\games\spleef;
use pocketmine\block\Block;
use pocketmine\level\Location;
use pocketmine\math\Vector3;
class SpleefArenaConfig{
public $name;
/** @var Location */
public $spectatorSpawnLoc; // ssl? xD
/** @var Location */
public $playerPrepLoc;
/** @var Location[] */
public $playerStartLocs = [];
/** @var int */
public $fromx, $tox, $fromz, $toz;
/** @var int */
public $floors;
/** @var int includes the floor layer */
public $floorHeight;
/** @var int */
public $lowestY;
/** @var Block[] */
public $floorMaterials;
/** @var \pocketmine\item\Item[][] */
public $playerItems;
/** @var int */
public $minPlayers;
/** @var int */
public $minWaitTicks;
/** @var int */
public $maxWaitTicks;
/** @var int */
public $maxGameTicks;
public function getMaxPlayers(){
return count($this->playerStartLocs);
}
public function build(){
$materialMaxKey = count($this->floorMaterials) - 1;
$level = $this->playerPrepLoc->getLevel();
// $level->getServer()->getLogger()->debug("Start rebuilding of spleef $this->name");
for($floor = 0; $floor < $this->floors; $floor++){
$y = $this->lowestY + $floor * $this->floorHeight;
for($x = $this->fromx; $x <= $this->tox; $x++){
for($z = $this->fromz; $z <= $this->toz; $z++){
$level->setBlock(new Vector3($x, $y, $z), $this->floorMaterials[mt_rand(0, $materialMaxKey)], false, false);
}
}
}
// $level->getServer()->getLogger()->debug("Finished rebuilding of spleef $this->name");
}
}
<?php
namespace legionpe\games\spleef;
use legionpe\chat\Channel;
use legionpe\config\Settings;
use legionpe\games\Game;
use legionpe\LegionPE;
use legionpe\MysqlConnection;
use legionpe\session\Session;
use legionpe\utils\CallbackPluginTask;
use pocketmine\block\Block;
use pocketmine\command\Command;
use pocketmine\entity\Entity;
use pocketmine\entity\Snowball;
use pocketmine\event\block\BlockBreakEvent;
use pocketmine\event\entity\EntityDamageByChildEntityEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\inventory\InventoryPickupItemEvent;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\event\player\PlayerMoveEvent;
use pocketmine\event\player\PlayerRespawnEvent;
use pocketmine\inventory\PlayerInventory;
use pocketmine\item\GoldShovel;
use pocketmine\item\Item;
use pocketmine\item\ItemBlock;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\Byte;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Double;
use pocketmine\nbt\tag\Enum;
use pocketmine\nbt\tag\Float;
use pocketmine\nbt\tag\Short;
use pocketmine\Player;
use pocketmine\scheduler\PluginTask;
class SpleefGame extends PluginTask implements Game{
/** @var LegionPE */
private $main;
/** @var \legionpe\chat\Channel */
private $spleefChan;
/** @var SpleefArena[] */
private $arenas = [];
/** @var SpleefSessionData[] */
private $playerData = [];
private $spleefWorld;
public function __construct(LegionPE $main){
parent::__construct($main);
$this->main = $main;
$this->spleefChan = $this->getMain()->getChannelManager()->joinChannel($main, "spleef", Channel::CLASS_MODULAR);
$this->getMain()->getServer()->getPluginManager()->registerEvents($this, $main);
$this->getMain()->getServer()->getScheduler()->scheduleDelayedRepeatingTask($this, 1, 1);
for($id = 1; $id <= Settings::spleef_arenaCnt(); $id++){
$this->arenas[$id] = new SpleefArena($this, $id);
$this->arenas[$id]->reset();
}
$this->spleefWorld = $this->getMain()->getServer()->getLevelByName("world_spleef");
$this->getMain()->getServer()->getScheduler()->scheduleRepeatingTask(new CallbackPluginTask($this->getMain(), function(){
for($id = 1; $id <= Settings::spleef_arenaCnt(); $id++){
Settings::spleef_updateArenaSigns($this->arenas[$id]);
}
}), 40);
}
public function getMain(){
return $this->main;
}
public function getName(){
return "Spleef";
}
public function getSelectionItem(){
return new GoldShovel;
}
/**
* @param Session $session
* @return bool allow join
*/
public function onJoin(Session $session){
$this->playerData[$session->getUID()] = new SpleefSessionData($this, $session);
$session->tell("%s, welcome to Spleef.", $session->getPlayer()->getName());
$session->teleport($spawn = Settings::spleef_spawn($this->getMain()->getServer()));
$session->getPlayer()->setSpawn($spawn);
if($session->getPlayer()->getGamemode() === 2){
$session->getPlayer()->setGamemode(0);
}
return true;
}
/**
* @param Session $session
* @param bool $force
* @return bool allow quit or $force
*/
public function onQuit(Session $session, $force){
$data = $this->getPlayerData($session);
if(($arena = $data->getArena()) instanceof SpleefArena){
if($data->isPlaying()){
$session->tell("You are considered lost since you quitted spleef.");
$data->addLoss();
}
$arena->kick($data, "quitting spleef");
}
$data->update();
unset($this->playerData[$session->getUID()]);
return true;
}
public function getSessionId(){
return Session::SESSION_GAME_SPLEEF;
}
public function getDefaultChatChannel(){
return $this->spleefChan;
}
public function getDefaultCommands(){
return [
[
"name" => "slist",
"description" => "Spleef: show spleef arena statistics",
"usage" => "/slist"
]
];
}
/**
* This method will only get called when $session {@link Game::onJoin()}'ed the game
* and hasn't {@link Game#onQuit()}'ed yet.<br>
* Gracefully throw a {@link \RuntimeException} if it is
* @param Session $session
* @param string $msg
* @param bool $isACTION
* @return string
*/
public function formatChat(Session $session, $msg, $isACTION){
$tag = "";
if(isset($this->playerData[$uid = $session->getUID()]) and ($wins = $this->playerData[$uid]->getWins()) > 0){
$tag = "[§c" . $wins . "§7]";
}
$color = ($session->getRank() & (Settings::RANK_SECTOR_IMPORTANCE | Settings::RANK_SECTOR_PERMISSION) & ~Settings::RANK_IMPORTANCE_TESTER) ? "§f":"";
return $isACTION ? "* $tag$session $color$msg":"$tag$session: $color$msg";
}
/**
* @param Session $session
* @param string[] $args
* @return string
*/
public function onStats(Session $session, array $args){
if(isset($args[0]) and $args[0] === "top"){
$this->saveSessionsData();
$cols = 5;
if(isset($args[1]) and is_numeric($args[1])){
$cols = (int) $args[1];
}
if($cols > 30){
return "Can't fetch more than 30 rows.";
}
$result = $this->getMain()->getMySQLi()->query("SELECT(SELECT names FROM players where uid=spleef.uid)AS names,wins,losses,draws FROM spleef ORDER BY wins DESC LIMIT $cols", MysqlConnection::ALL);
$output = "";
$i = 1;
foreach($result as $row){
$output .= "#" . ($i++) . ") " . substr($row["names"], 0, -1) . ": " . $row["wins"] . " wins\n";
}
return $output;
}
$data = $this->getPlayerData($session);
return "Wins: {$data->getWins()}\nLosses: {$data->getLosses()}\nDraws: {$data->getDraws()}";
}
public function saveSessionsData(){
foreach($this->playerData as $data){
$data->update();
}
}
public function testCommandPermission(Command $cmd, Session $session){
if($cmd->getName() === "slist"){
return true;
}
return false;
}
public function onCommand(Command $cmd, array $args, Session $session){
if($cmd->getName() === "slist"){
if(!isset($args[0])){
$args[0] = "a";
}
if($args[0] === "a"){
$output = "";
foreach($this->arenas as $arena){
$output .= "$arena: ";
$output .= $arena->isPlaying() ? "playing":"waiting";
$output .= ". Players: ";
$closure = function(SpleefSessionData $data){
return $data->getSession()->getPlayer()->getName();
};
$output .= implode(", ", array_map($closure, $arena->getPlayers()));
$output .= ". Spectators: ";
$output .= implode(", ", array_map($closure, $arena->getSpectators()));
$output .= "\n";
}
$session->tell($output);
return;
}
if($args[0] === "p"){
$output = "";
foreach($this->playerData as $data){
$arena = $data->getArena();
$action = $data->isSpectating() ? "spectating":"playing";
$output .= "\n$data is $action in " . ($arena === null ? "null":$arena);
}
$session->tell($output);
return;
}
}
}
public function onMove(Session $session, PlayerMoveEvent $event){
/* nothing to do here */
}
public function onRespawn(PlayerRespawnEvent $event, Session $session){
$data = $this->getPlayerData($session);
if($data->isInArena()){
$this->rebouncePlayer($data);
}
}
public function onInventoryStateChange(Session $ses, $from, $to){
$data = $this->getPlayerData($ses);
if($data->isPlaying() and $to !== Session::INV_NORMAL_ACCESS){
$ses->tell("You cannot change your inventory type when you are playing in a match.");
return false;
}
return true;
}
public function rebouncePlayer(SpleefSessionData $data){
if($data->isInArena()){
if($data->isSpectating()){
$data->getSession()->teleport($data->getArena()->getConfig()->spectatorSpawnLoc);
}
else{
$arena = $data->getArena();
$arena->kick($data, "you fell out of the arena");
$arena->broadcast("$data has fallen!");
$data->addLoss();
}
}
else{
$data->getSession()->teleport(Settings::spleef_spawn($this->getMain()->getServer()));
}
}
/**
* @param PlayerInteractEvent $event
* @priority HIGHEST
*/
public function onTouchBlock(PlayerInteractEvent $event){
$player = $event->getPlayer();
$session = $this->getMain()->getSessions()->getSession($player);
if(!($session instanceof Session) or !$session->inSession($this)){
return;
}
$event->setCancelled($event->getFace() !== 0xFF);
if($event->getFace() === 0xFF){
return;
}
Settings::spleef_getType($event->getBlock(), $arenaId, $spectator);
if($arenaId !== -1){
$data = $this->getPlayerData($session);
if($data->isInArena()){
$this->rebouncePlayer($data);
return;
}
$arena = $this->getArena($arenaId);
if($spectator === 2){
$arena->kick($data, "Spectator quit", false);
}
elseif($spectator === 1){
$arena->spectate($this->getPlayerData($session));
}
else{
if($arena->isPlaying()){
$session->tell("A match is going on in $arena!");
return;
}
if($arena->isFull()){
$session->tell("The arena is already full!");
return;
}
$arena->join($data);
}
}
else{
$data = $this->getPlayerData($session);
if($data->isPlaying() and $data->getArena()->isPlaying() and Settings::spleef_isArenaFloor($event->getBlock())){
$event->setCancelled(false);
}
elseif($result = Settings::spleef_incineratorInfo($event->getBlock())){
if($event->getItem()->getId() !== Item::AIR){
$event->setCancelled();
$item = $event->getItem();
$player->getInventory()->setItemInHand(Item::get(Item::AIR, 0, 1));
$player->getInventory()->sendContents($player->getInventory()->getViewers());
for($x = 936; $x <= 938; $x++){
$this->spleefWorld->setBlock(new Vector3($x, 21, -13), Block::get(Block::JACK_O_LANTERN), false, false);
}
for($z = -16; $z <= -14; $z++){
$this->spleefWorld->setBlock(new Vector3(935, 21, $z), Block::get(Block::JACK_O_LANTERN, 1), false, false);
}
$motion = $result[0]->subtract($player)->multiply(0.3);
$source = $player->add(0, 1.3);
$itemEntity = Entity::createEntity("Item", $player->getLevel()->getChunk($source->getX() >> 4, $source->getZ() >> 4), new Compound("", [
"Pos" => new Enum("Pos", [
new Double("", $source->getX()),
new Double("", $source->getY()),
new Double("", $source->getZ())
]),
"Motion" => new Enum("Motion", [
new Double("", $motion->x),
new Double("", $motion->y),
new Double("", $motion->z)
]),
"Rotation" => new Enum("Rotation", [
new Float("", lcg_value() * 360),
new Float("", 0)
]),
"Health" => new Short("Health", 1),
"Item" => new Compound("Item", [
"id" => new Short("id", $item->getId()),
"Damage" => new Short("Damage", $item->getDamage()),
"Count" => new Byte("Count", $item->getCount())
]),
"PickupDelay" => new Short("PickupDelay", 0x7FFF)
]));
$itemEntity->spawnToAll();
$this->getMain()->getServer()->getScheduler()->scheduleDelayedTask(new CallbackPluginTask($this->getMain(), function(\pocketmine\entity\Item $item, Vector3 $pos){
$item->teleport($pos);
}, $itemEntity, $result[0]), 10);
$this->getMain()->getServer()->getScheduler()->scheduleDelayedTask(new CallbackPluginTask($this->getMain(), function(\pocketmine\entity\Item $item, Vector3 $target){
$item->setMotion($target->subtract($item)->multiply(0.1));
}, $itemEntity, $result[1]), 40);
$this->getMain()->getServer()->getScheduler()->scheduleDelayedTask(new CallbackPluginTask($this->getMain(), function(\pocketmine\entity\Item $item){
$item->kill();
}, $itemEntity), 70);
$this->getMain()->getServer()->getScheduler()->scheduleDelayedTask(new CallbackPluginTask($this->getMain(), function(){
for($x = 936; $x <= 938; $x++){
$this->spleefWorld->setBlock(new Vector3($x, 21, -13), Block::get(Block::PUMPKIN), false, false);
}
for($z = -16; $z <= -14; $z++){
$this->spleefWorld->setBlock(new Vector3(935, 21, $z), Block::get(Block::PUMPKIN, 1), false, false);
}
}), 80);
}
}
}
}
/**
* @param BlockBreakEvent $event
* @priority HIGH
*/
public function onBlockBreak(BlockBreakEvent $event){
$player = $event->getPlayer();
$session = $this->getMain()->getSessions()->getSession($player);
if(!$session->inSession($this)){
return;
}
$data = $this->getPlayerData($session);
if($data->isPlaying() and $data->getArena()->isPlaying() and Settings::spleef_isArenaFloor($event->getBlock())){
$event->setCancelled(false);
}
}
public function onDamage(EntityDamageEvent $event){
$damaged = $event->getEntity();
if(!($damaged instanceof Player) or !(($session = $this->getMain()->getSessions()->getSession($damaged)) instanceof Session) or !$session->inSession($this)){
return;
}
if($event instanceof EntityDamageByChildEntityEvent){
$entity = $event->getDamager();
if($entity instanceof Player){
$ses = $this->main->getSessions()->getSession($entity);
if($ses instanceof Session and $ses->inSession($this)){
$data = $this->getPlayerData($ses);
if($data->isPlaying() and $data->getArena()->isPlaying()){
$projectile = $event->getChild();
if($projectile instanceof Snowball){
$event->setCancelled(false);
$event->setKnockBack($event->getKnockBack() * 2);
}
}
}
}
}
}
public function onPickup(InventoryPickupItemEvent $event){
$inv = $event->getInventory();
if(!($inv instanceof PlayerInventory)){
return;
}
$player = $inv->getHolder();
if(!($player instanceof Player)){
return;
}
$session = $this->getMain()->getSessions()->getSession($player);
if(!$session->inSession($this)){
return;
}
$item = $event->getItem();
if($item instanceof ItemBlock){
if($item->getBlock() === Block::SNOW_BLOCK){
$event->setCancelled();
}
}
}
public function __toString(){
return $this->getName();
}
public function onDisable(){
/* nothing to do here */
}
public function onRun($tick){
foreach($this->arenas as $arena){
$arena->tick();
}
}
public function getArena($id){
return isset($this->arenas[$id]) ? $this->arenas[$id] : null;
}
public function getPlayerData(Session $session){
return isset($this->playerData[$session->getUID()]) ? $this->playerData[$session->getUID()]:null;
}
public function countPlayers(){
return count($this->playerData);
}
}
<?php
namespace legionpe\games\spleef;
use legionpe\MysqlConnection;
use legionpe\session\Session;
class SpleefSessionData{
/** @var SpleefGame */
private $game;
/** @var Session */
private $session;
private $arena = 0;
private $spectating = false;
private $data = [];
private $needChange = false;
public function __construct(SpleefGame $game, Session $session){
$this->game = $game;
$this->session = $session;
$this->data = $game->getMain()->getMySQLi()->query("SELECT * FROM spleef WHERE uid=%d;", MysqlConnection::ASSOC, $session->getUID());
if(!is_array($this->data)){
$this->data = $this->getDefaultMysqlDataArray();
}
else{
foreach(array_keys($this->data) as $k){
$this->data[$k] = (int) $this->data[$k];
}
}
}
public function getArena(){
return $this->game->getArena($this->arena);
}
/**
* @param int $id
* @param bool $spec
*/
public function joinArena($id, $spec){
$this->arena = $id;
$this->spectating = $spec;
}
public function quitArena(){
$this->arena = 0;
$this->spectating = false;
}
/**
* @return bool
*/
public function isInArena(){
return $this->arena > 0;
}
public function isPlaying(){
return $this->isInArena() and !$this->spectating;
}
/**
* @return bool
*/
public function isSpectating(){
return $this->spectating;
}
/**
* @return Session
*/
public function getSession(){
return $this->session;
}
public function getDefaultMysqlDataArray(){
return [
"uid" => $this->session->getUID(),
"wins" => 0,
"losses" => 0,
"draws" => 0
];
}
public function getWins(){
return $this->data["wins"];
}
public function getLosses(){
return $this->data["losses"];
}
public function getDraws(){
return $this->data["draws"];
}
public function addWin(){
$wins = ++$this->data["wins"];
$this->needChange = true;
$this->session->tell("You totally won $wins match(es).");
return $wins;
}
public function addLoss(){
$losses = ++$this->data["losses"];
$this->needChange = true;
$this->session->tell("You totally lost $losses match(es).");
return $losses;
}
public function addDraw(){
$draws = ++$this->data["draws"];
$this->needChange = true;
$this->session->tell("You totally have $draws draw(s).");
return $draws;
}
public function update(){
$this->game->getMain()->getMySQLi()->query(
'INSERT INTO spleef(uid,wins,losses,draws,current_streak)VALUES(%d,%d,%d,%d,%d)ON DUPLICATE KEY UPDATE wins=VALUES(wins),losses=VALUES(losses),draws=VALUES(draws),current_streak=VALUES(current_streak);',
MysqlConnection::RAW, (int) $this->session->getUID(), (int) $this->getWins(), (int) $this->getLosses(), (int) $this->getDraws(), 0);
}
public function __toString(){
return $this->session->__toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment