Merge remote-tracking branch 'origin/master'

This commit is contained in:
Michael Yoo 2013-11-25 18:57:33 +10:30
commit 624219f680
5 changed files with 215 additions and 3 deletions

View File

@ -6,9 +6,8 @@ Before contributing to PocketMine-MP, please read this.
## I've a question ## I've a question
* For questions, please refer to the _#mcpedevs_ IRC * For questions, please refer to the _#pocketmine_ or _#mcpedevs_ IRC channel on Freenode. There is a [WebIRC](http://webchat.freenode.net?channels=pockdetmine,mcpedevs&uio=d4) if you want.
channel on Freenode. There is a [WebIRC](http://webchat.freenode.net?channels=mcpedevs&uio=d4) if you want. * You can ask directly to _[@PocketMine](https://twitter.com/PocketMine)_ in Twitter, but don't expect an inmediate reply.
* You can ask directly to _[@PocketMine](https://twitter.com/PocketMine)_ in Twitter.
## I want to create an issue ## I want to create an issue
* First, use the [Issue Search](https://github.com/PocketMine/PocketMine-MP/search?ref=cmdform&type=Issues) to check if anyone has reported it. * First, use the [Issue Search](https://github.com/PocketMine/PocketMine-MP/search?ref=cmdform&type=Issues) to check if anyone has reported it.

164
src/API/AchievementAPI.php Normal file
View File

@ -0,0 +1,164 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class AchievementAPI{
public static $achievements = array(
/*"openInventory" => array(
"name" => "Taking Inventory",
"requires" => array(),
),*/
"mineWood" => array(
"name" => "Getting Wood",
"requires" => array(
//"openInventory",
),
),
"buildWorkBench" => array(
"name" => "Benchmarking",
"requires" => array(
"mineWood",
),
),
"buildPickaxe" => array(
"name" => "Time to Mine!",
"requires" => array(
"buildWorkBench",
),
),
"buildFurnace" => array(
"name" => "Hot Topic",
"requires" => array(
"buildPickaxe",
),
),
"acquireIron" => array(
"name" => "Acquire hardware",
"requires" => array(
"buildFurnace",
),
),
"buildHoe" => array(
"name" => "Time to Farm!",
"requires" => array(
"buildWorkBench",
),
),
"makeBread" => array(
"name" => "Bake Bread",
"requires" => array(
"buildHoe",
),
),
"bakeCake" => array(
"name" => "The Lie",
"requires" => array(
"buildHoe",
),
),
"buildBetterPickaxe" => array(
"name" => "Getting an Upgrade",
"requires" => array(
"buildPickaxe",
),
),
"buildSword" => array(
"name" => "Time to Strike!",
"requires" => array(
"buildWorkBench",
),
),
"diamonds" => array(
"name" => "DIAMONDS!",
"requires" => array(
"acquireIron",
),
),
);
function __construct(){
}
public static function broadcastAchievement(Player $player, $achievementId){
if(isset(self::$achievements[$achievementId])){
$result = ServerAPI::request()->api->dhandle("achievement.broadcast", array("player" => $player, "achievementId" => $achievementId));
if($result !== false and $result !== true){
if(ServerAPI::request()->api->getProperty("announce-player-achievements") == true){
ServerAPI::request()->api->chat->broadcast($player->username." has just earned the achievement ".self::$achievements[$achievementId]["name"]);
}else{
$player->sendChat("You have just earned the achievement ".self::$achievements[$achievementId]["name"]);
}
}
return true;
}
return false;
}
public static function addAchievement($achievementId, $achievementName, array $requires = array()){
if(!isset(self::$achievements[$achievementId])){
self::$achievements[$achievementId] = array(
"name" => $achievementName,
"requires" => $requires,
);
return true;
}
return false;
}
public static function hasAchievement(Player $player, $achievementId){
if(!isset(self::$achievements[$achievementId]) or !isset($player->achievements)){
$player->achievements = array();
return false;
}
if(!isset($player->achievements[$achievementId]) or $player->achievements[$achievementId] == false){
return false;
}
return true;
}
public static function grantAchievement(Player $player, $achievementId){
if(isset(self::$achievements[$achievementId]) and !self::hasAchievement($player, $achievementId)){
foreach(self::$achievements[$achievementId]["requires"] as $requerimentId){
if(!self::hasAchievement($player, $requerimentId)){
return false;
}
}
if(ServerAPI::request()->api->dhandle("achievement.grant", array("player" => $player, "achievementId" => $achievementId)) !== false){
$player->achievements[$achievementId] = true;
self::broadcastAchievement($player, $achievementId);
return true;
}else{
return false;
}
}
return false;
}
public static function removeAchievement(Player $player, $achievementId){
if(self::hasAchievement($player, $achievementId)){
$player->achievements[$achievementId] = false;
}
}
public function init(){
}
}

View File

@ -459,6 +459,7 @@ class PlayerAPI{
"health" => 20, "health" => 20,
"lastIP" => "", "lastIP" => "",
"lastID" => 0, "lastID" => 0,
"achievements" => array(),
); );
if(!file_exists(DATA_PATH."players/".$iname.".yml")){ if(!file_exists(DATA_PATH."players/".$iname.".yml")){

View File

@ -61,6 +61,7 @@ class ServerAPI{
"memory-limit" => "128M", "memory-limit" => "128M",
"last-update" => false, "last-update" => false,
"white-list" => false, "white-list" => false,
"announce-player-achievements" => true,
"spawn-protection" => 16, "spawn-protection" => 16,
"view-distance" => 10, "view-distance" => 10,
"max-players" => 20, "max-players" => 20,

View File

@ -58,6 +58,7 @@ class Player{
public $windowCnt = 2; public $windowCnt = 2;
public $windows = array(); public $windows = array();
public $blocked = true; public $blocked = true;
public $achievements = array();
public $chunksLoaded = array(); public $chunksLoaded = array();
private $chunksOrder = array(); private $chunksOrder = array();
private $lastMeasure = 0; private $lastMeasure = 0;
@ -216,6 +217,7 @@ class Player{
public function save(){ public function save(){
if($this->entity instanceof Entity){ if($this->entity instanceof Entity){
$this->data->set("achievements", $this->achievements);
$this->data->set("position", array( $this->data->set("position", array(
"level" => $this->entity->level->getName(), "level" => $this->entity->level->getName(),
"x" => $this->entity->x, "x" => $this->entity->x,
@ -536,8 +538,10 @@ class Player{
} }
switch($data["entity"]->type){ switch($data["entity"]->type){
case WOOD: case WOOD:
AchievementAPI::grantAchievement($this, "mineWood");
break; break;
case DIAMOND: case DIAMOND:
AchievementAPI::grantAchievement($this, "diamond");
break; break;
} }
}elseif($data["entity"]->level === $this->level){ }elseif($data["entity"]->level === $this->level){
@ -749,6 +753,40 @@ class Player{
}else{ }else{
$this->setSlot($slot, BlockAPI::getItem($item->getID(), $item->getMetadata(), $s->count + $item->count), false); $this->setSlot($slot, BlockAPI::getItem($item->getID(), $item->getMetadata(), $s->count + $item->count), false);
} }
switch($item->getID()){
case WORKBENCH:
AchievementAPI::grantAchievement($this, "buildWorkBench");
break;
case WOODEN_PICKAXE:
AchievementAPI::grantAchievement($this, "buildPickaxe");
break;
case FURNACE:
AchievementAPI::grantAchievement($this, "buildFurnace");
break;
case WOODEN_HOE:
AchievementAPI::grantAchievement($this, "buildHoe");
break;
case BREAD:
AchievementAPI::grantAchievement($this, "makeBread");
break;
case CAKE:
AchievementAPI::grantAchievement($this, "bakeCake");
break;
case STONE_PICKAXE:
case GOLD_PICKAXE:
case IRON_PICKAXE:
case DIAMOND_PICKAXE:
AchievementAPI::grantAchievement($this, "buildBetterPickaxe");
break;
case WOODEN_SWORD:
AchievementAPI::grantAchievement($this, "buildSword");
break;
case DIAMOND:
AchievementAPI::grantAchievement($this, "diamond");
break;
}
} }
} }
return $res; return $res;
@ -1209,6 +1247,7 @@ class Player{
} }
$this->data->set("inventory", $inv); $this->data->set("inventory", $inv);
} }
$this->achievements = $this->data->get("achievements");
$this->data->set("caseusername", $this->username); $this->data->set("caseusername", $this->username);
$this->inventory = array(); $this->inventory = array();
foreach($this->data->get("inventory") as $slot => $item){ foreach($this->data->get("inventory") as $slot => $item){
@ -1969,6 +2008,14 @@ class Player{
)); ));
break; break;
} }
if($tile->class === TILE_FURNACE and $data["slot"] == 2){
switch($slot->getID()){
case IRON_INGOT:
AchievementAPI::grantAchievement($this, "acquireIron");
break;
}
}
if($item->getID() !== AIR and $slot->getID() == $item->getID()){ if($item->getID() !== AIR and $slot->getID() == $item->getID()){
if($slot->count < $item->count){ if($slot->count < $item->count){