Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

update xml files, add update stamina, fix cache

  • Loading branch information...
commit c9a9b300e1b082799ae49bc9d00c6f942be60cf2 1 parent 777f06d
unknown authored
View
38 do.php
@@ -1,7 +1,7 @@
<?php
- $player_id = $_GET['player_id'];
- $session_id = $_GET['session_id'];
+ $playerId = $_GET['playerId'];
+ $sessionId = $_GET['sessionId'];
//required parameter validations.
@@ -13,16 +13,44 @@
$data = null;
switch($method)
{
- case 'add_to_deck':
- $data = add_to_deck($_POST['player_id'], $_POST['deck_id'], $_POST['card_id']);
+ case 'addToDeck':
+ $data = add_to_deck($_POST['playerId'], $_POST['deckId'], $_POST['cardId']);
break;
case 'remove_from_deck':
- $data = remove_from_deck($_POST['player_id'], $_POST['deck_id'], $_POST['card_order']);
+ $data = remove_from_deck($_POST['player_id'], $_POST['deckId'], $_POST['cardOrder']);
break;
case 'test':
require_once('inc/DataCache.php');
$data = json_encode(get_all_cards());
break;
+ case 'testCard':
+ require_once('inc/DataCache.php');
+ $data = json_encode(get_all_cards());
+ break;
+
+ case 'testStamina':
+ require_once('inc/Common.php');
+ require_once('inc/DataCache.php');
+ $playerId = $_GET['playerId'];
+ $dec_sta = $_GET['useStamina'];
+ $player = getPlayerInfo($playerId);
+ debug_print($player);
+ $ret = updateStamina($player, $dec_sta);
+ break;
+
+ case 'startMission':
+ $missionId = $_GET['missionId'];
+ require_once('inc/BattleManager.php');
+ startMission($playerId, $missionId);
+ break;
+
+ case 'clearCache':
+ require_once('inc/CacheManager.php');
+ CacheManager::clearCache();
+ break;
+
+ default:
+
}
print_r($data);
View
58 inc/BattleManager.php
@@ -1,4 +1,6 @@
-<?php
+<?php
+
+
function initMission($mid)
{
@@ -14,8 +16,60 @@ function initMission($mid)
}
}
-function start_mission($player_id, $mession_id)
+function startMission($playerId, $missionId)
{
+ require_once('inc/Common.php');
+ require_once('inc/DataCache.php');
+ require_once('inc/Battle.class.php');
+ //check if player is already engaged in battle
+ $player = getPlayerInfo($playerId);
+ $battle = $player->current_battle;
+ if ($battle) { //not null
+ //remove curent battle
+ }
+
+ $mission = getMissionInfo($missionId);
+
+ //init
+ $battle = new Battle();
+
+ $battle->id = $missionId;
+
+ $battle->start_time = time();
+ /*
+ public $end_time;
+
+ //????
+ public $version;
+
+ //????,??vs???
+ public $player_role;
+ public $attacker_name;
+ public $defender_name;
+ public $attacher_deck;
+ public $defender_deck;
+ public $attacker_shuffle;
+ public $defender_shuffle;
+
+ //????
+ public $win_condition;
+ public $win_condition_param;
+ public $lose_condition;
+ public $lose_condition_param;
+ public $current_round;
+ public $current_player;
+
+ //??????????
+ public $actions;
+
+ //????
+ public $battle_result;
+
+ */
+
+ //save to cache
+ $player['current_battle'] = $battle;
+ updatePlayerInfo($player);
}
View
21 inc/CacheManager.php
@@ -12,7 +12,8 @@ public static function setValue($key, $group = null, $value, $duration)
{
$cacheOption = array(
'cacheDir' => 'tmp/',
- 'lifeTime' => $duration
+ 'lifeTime' => $duration,
+ 'automaticSerialization' => true
);
$cache = new Cache_Lite($cacheOption);
@@ -26,7 +27,8 @@ public static function setValue($key, $group = null, $value, $duration)
public static function getValue($key, $group = null)
{
$cacheOption = array(
- 'cacheDir' => 'tmp/'
+ 'cacheDir' => 'tmp/',
+ 'automaticSerialization' => true
);
$cache = new Cache_Lite($cacheOption);
@@ -34,6 +36,21 @@ public static function getValue($key, $group = null)
return $cache->get($key, $group);
}
+ /**
+ *
+ * Clear Cache
+ */
+ public static function clearCache()
+ {
+ $cacheOption = array(
+ 'cacheDir' => 'tmp/'
+ );
+
+ $cache = new Cache_Lite($cacheOption);
+
+ return $cache->clean();
+ }
+
}
?>
View
82 inc/Common.php
@@ -1,5 +1,18 @@
<?php
+
+//print an object or array for debug information
+function debug_print($obj) {
+ echo '<pre>';
+ print_r($obj);
+ echo '</pre>';
+}
+
+
+//********************************
+// XML functions
+//********************************
+
//parse xml to array
//parameters:
// file_name: the name of the xml file
@@ -117,13 +130,6 @@ function xml2array($file_name, $index_base=0, $value_key=null) {
}
-//print an object or array for debug information
-function debug_print($obj) {
- echo '<pre>';
- print_r($obj);
- echo '</pre>';
-}
-
function getMissionsFromXML() {
$obj = xml2array('xml/missions.xml', 1);
@@ -148,4 +154,66 @@ function getBuffsFromXML() {
+
+
+
+
+//********************************
+// Stamina calculation
+//********************************
+
+
+//return:
+//>=0 : successfully consumed
+//<0 : not enough stamina
+function updateStamina(&$player, $stamina_consume=0) {
+ debug_print('Player had '.$player['stamina'].' stamina by '.$player['stamina_last_update']);
+ debug_print('Player uses '.$stamina_consume.' points of stamina');
+
+ $current_time = time();
+ $new_stamina = $player['stamina'];
+ $prev_min = floor($player['stamina_last_update'] / 60);
+ $current_min = floor($current_time / 60);
+ require_once('inc/Const.php');
+ if ($current_min > $prev_min) {
+ $new_stamina += ($current_min - $prev_min) * constant('STAMINA_PER_MIN');
+ if ($new_stamina > constant('STAMINA_MAX')) $new_stamina = constant('STAMINA_MAX');
+ }
+ $result = $new_stamina;
+ if ($stamina_consume > 0 ) {
+ if ($new_stamina > $stamina_consume) {
+ $new_stamina -= $stamina_consume;
+ $player['stamina'] = $new_stamina;
+ $player['stamina_last_update'] = $current_time;
+ $result = $new_stamina;
+ } else {
+ $result = -1;
+ debug_print('Not enough stamina!');
+ }
+ }
+ updatePlayerInfo($player);
+ debug_print('Now player has '.$player['stamina'].' stamina by '.$player['stamina_last_update']);
+ return $result;
+}
+
+
+
+//********************************
+// time related
+//********************************
+
+
+
+
+
+//********************************
+//
+//********************************
+
+
+
+
+
+
+
?>
View
40 inc/Const.php
@@ -2,22 +2,34 @@
define('DECK_CARDS_MAX',20);
+ define('STAMINA_MAX',100);
+ define('STAMINA_PER_MIN',1);
+
+ define('CACHE_GROUP_SYSTEM', 'SYSTEM');
+ define('CACHE_GROUP_PLAYER', 'PLAYER');
+ define('CACHE_GROUP_MISSION', 'MISSION');
+ define('CACHE_GROUP_CARD', 'CARD');
+ define('CACHE_GROUP_BATTLE', 'BATTLE');
+
//卡牌类型:CARD_TYPE_
//主公:lord
//建筑:building
- //武将:hero
//士兵:unit
- // 武将和士兵统称army
//计策:spell
//装备:artifact
define('CARD_TYPE_LORD',0);
define('CARD_TYPE_BUILDING',1);
- define('CARD_TYPE_HERO',2);
- define('CARD_TYPE_UNIT',3);
- define('CARD_TYPE_SPELL',4);
- define('CARD_TYPE_ARTIFACT',5);
+ define('CARD_TYPE_UNIT',2);
+ define('CARD_TYPE_SPELL',3);
+ define('CARD_TYPE_ARTIFACT',4);
+ //卡牌在牌组中允许出现次数:CARD_OCCUR_
+ //唯一:UNIQUE
+ //可重复:MULTI
+ define('CARD_OCCUR_MULTI',0);
+ define('CARD_OCCUR_UNIQUE',1);
+
//卡牌势力或者阵营:CARD_FACTION_
//魏、蜀、吴、群
define('CARD_FACTION_WEI',0);
@@ -25,9 +37,23 @@
define('CARD_FACTION_WU',2);
define('CARD_FACTION_QUN',3);
+ //卡包: CARD_PACKAGE_
+ //非玩家:npc
+ //奖励:reward
+ //黄巾之乱:HUANGJIN
+ //官渡之战:GUANDU
+ //赤壁之战:CHIBI
+ //三国鼎立:SANGUO
+ define('CARD_PACKAGE_NPC',0);
+ define('CARD_PACKAGE_REWARD',1);
+ define('CARD_PACKAGE_HUANGJIN',2);
+ define('CARD_PACKAGE_GUANDU',3);
+ define('CARD_PACKAGE_CHIBI',4);
+ define('CARD_PACKAGE_SANGUO',5);
+
//卡牌稀有度: CARD_RARITY_
//普通common: black
- //特殊uncommon: silver
+ //罕见uncommon: silver
//稀有rare: gold
//史诗epic: purple
define('CARD_RARITY_COMMON',0);
View
115 inc/DataCache.php
@@ -5,14 +5,13 @@
require_once('inc/DB.php');
/**
-* get_call_cards() will get all the cards from cache memory,
+* getAllCards() will get all the cards from cache memory,
* if the cards exist in cache memory, return all the cards
* if not, will load cards from xml file, save them into cache memory, and return all the cards
* Return: an array with all of the cards.
-* Examples: $allCards = get_all_cards();
+* Examples: $allCards = getAllCards();
*/
-function get_all_cards()
-{
+function getAllCards() {
// 1 day
$duration = 86400;
$group = "CARD";
@@ -20,8 +19,7 @@ function get_all_cards()
$cachedCards = CacheManager::getValue($key, $group);
- if(!$cachedCards)
- {
+ if(!$cachedCards) {
// parse cards from xml file
$cachedCards = getCardsFromXML();//xml2array(file_get_contents('./xml/cards.xml'), 1, 'attribute');
// save cards into cache memory
@@ -32,28 +30,70 @@ function get_all_cards()
}
/**
-* get_card_info() gets the detail information of one specified card
-* Arguments: $card_id - the card id
+* getCardInfo() gets the detail information of one specified card
+* Arguments: $cardId - the card id
* Return: A card object
-* Examples: $card_id = get_card_info(10001);
+* Examples: $cardId = getCardInfo(10001);
*/
-function get_card_info($card_id)
-{
+function getCardInfo($cardId) {
$group = "CARD";
- $cachedCard = CacheManager::getValue($card_id, $group);
- if(!$cachedCard)
- {
+ $cachedCard = CacheManager::getValue($cardId, $group);
+ if(!$cachedCard) {
// parse cards from xml file
- $allCards = get_all_cards();
- $cachedCard = $allCards[$card_id];
+ $allCards = getAllCards();
+ $cachedCard = $allCards[$cardId];
// save cards into cache memory
- CacheManager::setValue($card_id, $group, $cachedCard, 86400);
+ CacheManager::setValue($cardId, $group, $cachedCard, 86400);
}
- return cachedCards;
+ return $cachedCard;
}
+
+
+
+
+
+
+
+
+
+
+
+
+function getAllMissions() {
+ // 1 day
+ $duration = 86400;
+ $group = "MISSION";
+ $key = "all_missions";
+
+ $missions = CacheManager::getValue($key, $group);
+
+ if(!$missions) {
+ $missions = getMissionsFromXML();
+ CacheManager::setValue($key, $group, $missions, $duration);
+ }
+
+ return $missions;
+}
+
+function getMissionInfo($missionId) {
+ $group = "MISSION";
+
+ $mission = CacheManager::getValue($missionId, $group);
+ if(!$mission) {
+ $allMissions = getAllMissions();
+ $mission = $allMissions[$missionId];
+ CacheManager::setValue($missionId, $group, $mission, 86400);
+ }
+
+ return $mission;
+}
+
+
+
+
/**
* get_player_info() gets detail information of a player
* if the player's info already exist in cache memory, then return the player
@@ -61,29 +101,44 @@ function get_card_info($card_id)
* Arguments: $player_id - the player's id
* Return: A player object contains all detail information of the player
*/
-function get_player_info($player_id)
-{
+function getPlayerInfo($playerId) {
$group = "PLAYER";
- $cachedPlayer = CacheManager::getValue($player_id, $group);
- if(!$cachedPlayer)
- {
+ $playerId = mysql_real_escape_string($playerId);
+ $player = CacheManager::getValue($playerId, $group);
+ if(!$player) {
//get player's information from database
$db = DatabaseConnection::getInstance();
- $cachedPlayer = $db->query('SELECT * FROM player WHERE id =' . $player_id);
- //save into cache memory
- CacheManager::setValue($player_id, $group, $cachedPlayer, 3600);
+ $record = $db->query('SELECT * FROM player WHERE id =' . $playerId);
+
+ if ($record) {
+ $player = mysql_fetch_array($record);
+ //save into cache memory
+ CacheManager::setValue($playerId, $group, $player, 3600);
+ } else {
+ //error, not found
+ }
+
}
- return $cachedPlayer;
+ return $player;
}
/**
* update_player_info() saves player's information into cache memory
*/
-function update_player_info($player)
-{
- CacheManager::setValue($player->id, 'PLAYER', $player, 3600);
+function updatePlayerInfo($player) {
+ CacheManager::setValue($player['id'], 'PLAYER', $player, 3600);
+}
+
+
+
+/*
+function getCurrentBattleByPlayer($playerId) {
+ $group = 'BATTLE';
+ $battle = CacheManager::getValue($playerId, $group);
+ return $battle;
}
+*/
View
2  inc/Player.class.php
@@ -40,7 +40,7 @@ class Player
public $guild_rank;
//竞技场
- public $arena_point;
+ public $arena_rating;
public $arena_rank;
//成就
View
86 sql/install.sql
@@ -0,0 +1,86 @@
+-- phpMyAdmin SQL Dump
+-- version 3.3.9
+-- http://www.phpmyadmin.net
+--
+-- Host: localhost
+-- Generation Time: Aug 23, 2011 at 08:15 AM
+-- Server version: 5.5.8
+-- PHP Version: 5.3.5
+
+SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
+
+--
+-- Database: `ccg`
+--
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `player`
+--
+
+DROP TABLE IF EXISTS `player`;
+CREATE TABLE IF NOT EXISTS `player` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `name` varchar(50) NOT NULL,
+ `type` int(2) unsigned NOT NULL,
+ `auth` varchar(100) NOT NULL,
+ `email` varchar(255) NOT NULL,
+ `create_time` bigint(10) unsigned NOT NULL,
+ `copper` int(10) unsigned NOT NULL,
+ `gold` int(10) unsigned NOT NULL,
+ `exp` int(10) unsigned NOT NULL,
+ `level` int(10) unsigned NOT NULL,
+ `stamina` int(10) unsigned NOT NULL,
+ `stamina_last_update` bigint(10) unsigned NOT NULL,
+ `default_deck` int(10) unsigned NOT NULL DEFAULT '1',
+ `current_battle` int(10) unsigned DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=gbk AUTO_INCREMENT=3 ;
+
+--
+-- Dumping data for table `player`
+--
+
+INSERT INTO `player` (`id`, `name`, `type`, `auth`, `email`, `create_time`, `copper`, `gold`, `exp`, `level`, `stamina`, `stamina_last_update`, `default_deck`, `current_battle`) VALUES
+(1, 'Philip', 1, '111111', 'admin@kayoku.com', 1, 100, 100, 0, 1, 100, 1, 1, NULL);
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `player_cards`
+--
+
+DROP TABLE IF EXISTS `player_cards`;
+CREATE TABLE IF NOT EXISTS `player_cards` (
+ `player_id` int(10) unsigned NOT NULL,
+ `card_id` int(10) unsigned NOT NULL,
+ `count` int(10) unsigned NOT NULL,
+ PRIMARY KEY (`player_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=gbk;
+
+--
+-- Dumping data for table `player_cards`
+--
+
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `player_decks`
+--
+
+DROP TABLE IF EXISTS `player_decks`;
+CREATE TABLE IF NOT EXISTS `player_decks` (
+ `player_id` int(10) unsigned NOT NULL,
+ `deck_id` int(10) unsigned NOT NULL,
+ `order` int(10) unsigned NOT NULL,
+ `card_id` int(10) unsigned NOT NULL,
+ `antifact_id` int(10) unsigned DEFAULT NULL,
+ UNIQUE KEY `player_deck_index` (`player_id`,`deck_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=gbk;
+
+--
+-- Dumping data for table `player_decks`
+--
+
View
3  xml/buffs.xml
@@ -1,4 +1,5 @@
-<buffs version="0.0.1">
+<?xml version="1.0" encoding="UTF-8 "?>
+<buffs version="0.0.1">
<buff id="1"
name="士气上升"
View
89 xml/cards.xml
@@ -1,12 +1,17 @@
-<cards version="0.0.1">
+<?xml version="1.0" encoding="UTF-8 "?>
+<cards version="0.0.1">
+<!--核心包-->
+
+ <!--注册时,二选一-->
<card id="1"
- name="张角"
- type="Commander"
- package="Original"
- rarity="Special"
- faction="Qun"
- hp="12"
+ name="川哥"
+ type="lord"
+ package="huangjin"
+ rarity="common"
+ occur="1"
+ faction="qun"
+ hp="5"
att=""
mp="4"
image=""
@@ -14,12 +19,29 @@
<skill id="1" faction="Shu" target="Select" cost="0" effect="1" last="1"/>
</card>
+ <!--注册时,二选一-->
<card id="2"
- name="黄巾士兵"
- type="Army"
- package="Original"
- rarity="Common"
- faction="Qun"
+ name="越妹"
+ type="lord"
+ package="huangjin"
+ rarity="common"
+ occur="1"
+ faction="qun"
+ hp="5"
+ att=""
+ mp="4"
+ image=""
+ >
+ <skill id="1" faction="Shu" target="Select" cost="0" effect="1" last="1"/>
+ </card>
+
+ <card id="3"
+ name="民夫"
+ type="unit"
+ package="huangjin"
+ rarity="common"
+ occur="0"
+ faction="qun"
hp="1"
att="1"
mp="1"
@@ -27,12 +49,13 @@
>
</card>
- <card id="3"
- name="黄巾精兵"
- type="Army"
- package="Original"
- rarity="Common"
- faction="Qun"
+ <card id="4"
+ name="民兵"
+ type="unit"
+ package="huangjin"
+ rarity="common"
+ occur="0"
+ faction="qun"
hp="2"
att="1"
mp="1"
@@ -41,5 +64,35 @@
</card>
+ <card id="5"
+ name="山贼头目"
+ type="lord"
+ package="huangjin"
+ rarity="common"
+ occur="1"
+ faction="qun"
+ hp="7"
+ att="0"
+ mp="2"
+ image=""
+ >
+ </card>
+
+
+ <card id="6"
+ name="山贼"
+ type="unit"
+ package="huangjin"
+ rarity="common"
+ occur="0"
+ faction="qun"
+ hp="1"
+ att="2"
+ mp="1"
+ image=""
+ >
+ </card>
+
+
</cards>
View
49 xml/missions.xml
@@ -1,12 +1,45 @@
+<?xml version="1.0" encoding="UTF-8 "?>
<missions version="0.0.1">
+ <map id="1" name="" prereq="0">
- <mission id="1" prereq="0" coin="10" exp="10" win="defeat" lose="lose,50">
- <deck commander="1" size="5">
- <group id="1" select="5">
- <card id="2" multi="5" />
- </group>
- </deck>
- <preset />
- </mission>
+ <mission id="1" type="normal" name="新手上路(一)" prereq="0" coin="10" exp="10" win="defeat" lose="lose,50">
+ <deck lord="5" size="2">
+ <group id="1" select="2">
+ <card id="6" multi="2" />
+ </group>
+ </deck>
+ <preset />
+ <intro>
+ <message seq="1" image="" text=""/>
+ <message seq="2" image="" text=""/>
+ <message seq="3" image="" text=""/>
+ </intro>
+ <reward>
+ <item id="4" count="2" droprate="1" firsttimeonly="yes">
+ </reward>
+ </mission>
+ <mission id="2" type="normal" name="新手上路(二)" prereq="0" coin="10" exp="10" win="defeat" lose="lose,50">
+ <deck lord="5" size="4">
+ <group id="1" select="4">
+ <card id="6" multi="4" />
+ </group>
+ </deck>
+ <preset />
+ <intro>
+ <message seq="1" image="" text=""/>
+ <message seq="2" image="" text=""/>
+ <message seq="3" image="" text=""/>
+ </intro>
+ <reward>
+ <item id="6" count="1" droprate="1" firsttimeonly="yes">
+ </reward>
+ </mission>
+
+ <mission id="501" type="raid" name="县衙" prereq="2">
+ </mission>
+
+ <exit nextmap="2" prereq="2" />
+
+ </map>
</missions>
View
31 xml/skills.xml
@@ -1,16 +1,17 @@
-<skills version="0.0.1">
+<?xml version="1.0" encoding="UTF-8 "?>
+<skills version="0.0.1">
<skill id="1"
name="鼓舞"
- desc="Increase attack by %x, last %n rounds."
+ desc="Increase attack by %x, last %r rounds."
type="active"
icon=""
anim=""
/>
<skill id="2"
- name="辱骂"
- desc="Decrease attack by %x, last %n rounds."
+ name="呵斥"
+ desc="Decrease attack by %x, last %r rounds."
type="active"
icon=""
anim=""
@@ -34,7 +35,7 @@
<skill id="5"
name="冲阵"
- desc="Target has chance to get disorder, last %r rounds."
+ desc="Target has %c chance to get disorder, last %r rounds."
type="attack"
icon=""
anim=""
@@ -42,7 +43,7 @@
<skill id="6"
name="困敌"
- desc="Cannot attack, last %r rounds."
+ desc="Target cannot attack, last %r rounds."
type="active"
icon=""
anim=""
@@ -57,11 +58,27 @@
/>
<skill id="8"
- name="识破"
+ name="援助"
desc="Remove move imparing buffs."
type="active"
icon=""
anim=""
/>
+ <skill id="9"
+ name="火攻"
+ desc="Does %x damage to target."
+ type="active"
+ icon=""
+ anim=""
+ />
+
+ <skill id="10"
+ name="劫火"
+ desc="Does %x damage to all enemy."
+ type="active"
+ icon=""
+ anim=""
+ />
+
</skills>
Please sign in to comment.
Something went wrong with that request. Please try again.