Permalink
Browse files

- Add Shadow Keyword to fixtures

- Add Assassin Class to fixtures
- Add Shadar-kai Race to fixtures
- Update schema & models to:
-- add User model & user_id field in Player model
-- remove item field on power table, replace it with power_type enum
-- Add active boolean flag to power table for the spellbook
-- Add charge_type, charges_cur, and charges_max fields to the power table for future use with Charged powers.
- Add Power class constants for power types and charge types
- Add Power->isValidPowerType
- Add Power::typeDisplay
- Update Power->UsePower so it fails if the power is inactive
- Update Power->getClassDisplay to use the new power_type field
- Update Power->isDisabled to properly use the new power_type field
- Add Power->isActive
- Add Power->isSpellbookPower
- Add Player->activatePower
- Fix a bug in Feat->updateFromForm, where we end up having to set the feat id to null if it doesn't exist yet.
- Update the power edit form to handle the power_type field
- Update the player page, and related javascript, ajax, and css files to handle the Player Spellbook feature.
  • Loading branch information...
1 parent 35e5163 commit 1751c0d6bc3f3322cb900fb50d2d6787c826d246 @duaiwe committed Nov 29, 2009
@@ -10,7 +10,7 @@
$success = true;
-$data = empty($_POST['data'])?array():json_decode($_POST['data'],true);
+$data = empty($_REQUEST['data'])?array():json_decode($_REQUEST['data'],true);
$result = array();
switch($action) {
@@ -86,6 +86,24 @@
if( $surges != $char->surges_cur )
$result['surges_cur'] = $char->surges_cur;
break;
+ case 'setActivePower':
+ $p = $char->Powers->get($data['p_id']);
+ if( !$char->hasSpellbook() ) {
+ $msg->add("You do not have a spellbook.", Message::ERROR);
+ $success = false;
+ }
+ elseif( !$char->Powers->contains($data['p_id']) ) {
+ $msg->add(
+ sprintf("Unable to find Power '%s'.", $data['p_id']), Message::ERROR);
+ $success = false;
+ }
+ else {
+ $success = $char->activatePower($data['p_id']);
+ if( false !== $success ) {
+ $result['activePower'] = $success;
+ }
+ }
+ break;
}
if( $success ) {
@@ -291,6 +291,9 @@ li.noCheck div.listLabel {
#PowerTable tr.Used {
opacity : .5;
}
+#PowerTable tr.InActive {
+ display : none;
+}
#SkillTable, #FeatTable {
margin : 0 5px;
@@ -328,6 +331,9 @@ li.noCheck div.listLabel {
#SkillDiv {
float : left;
}
+#FeatForm {
+ margin-left : 375px;
+}
#FeatDiv {
- margin-left: 450px;
+ margin-left : 450px;
}
@@ -6,19 +6,15 @@
margin : 0 5px;
}
.shortStatColumn {
- width : 120px;
+ width : 130px;
margin : 0 5px;
}
.notesColumn {
width : 315px;
margin : 0 5px;
margin-left : 525px;
}
-.powerColumn {
- width : 500px;
- margin : 0 5px;
-}
-.skillColumn {
+.powerColumn, .skillColumn, .sbookColumn {
width : 500px;
margin : 0 5px;
}
@@ -130,4 +126,37 @@ a.ajaxLink:active {
}
#FeatTable {
width : 315px;
-}
+}
+
+#PlayerSpellbook {
+ display : none;
+}
+
+#SpellbookDailyTable, #SpellbookUtilityTable {
+ margin : 0 5px;
+ padding : 0;
+ border-spacing : 0 1px;
+ width : 240px;
+}
+#SpellbookDailyTable {
+ float: left;
+}
+#SpellbookUtilityTable {
+}
+
+#SpellbookDailyTable td, #SpellbookUtilityTable td,
+#SpellbookDailyTable th, #SpellbookUtilityTable th {
+ padding : 1px 4px;
+}
+
+#SpellbookDailyTable th, #SpellbookUtilityTable th {
+ padding-top : 5px;
+ text-align : left;
+}
+
+#SpellbookDailyTable tr.InActive, #SpellbookUtilityTable tr.InActive {
+ opacity : .5;
+ cursor : pointer;
+}
+
+
@@ -17,10 +17,12 @@ function playerProcessRequest(action, args) {
function parseProcessResult(data, textStatus) {
$('#surge_bonus,#damage_value,#health').val('');
-
for(var k in data) {
var v = data[k];
switch(k) {
+ case 'activePower':
+ setActivePower(v.pID, v.level);
+ break;
case 'refreshPowers':
animatePower('#PowerTable tr.Encounter');
if( v ) {
@@ -123,6 +125,30 @@ function animatePower(row, status) {
});
}
+function setActivePower(pID, level) {
+ var spellBookLevelRows = '.spellBookRow.l'+level;
+ var spellBookPowerRow = '#b'+pID;
+ var powerTableRow = '#r'+pID;
+ var powerTableLevelRows = '#PowerTable .l'+level;
+
+ //var levelSelect = '.l'+level;
+ //var powerRow = '#b'+pID;
+
+ // Add click bindings for all the spells of this level
+ $(spellBookLevelRows).click(function(){ playerProcessRequest('setActivePower', {
+ p_id: this.id.substring(1) }); });
+ // Remove the binding for our active power;
+ $(spellBookPowerRow).unbind('click');
+
+ $(spellBookLevelRows).fadeTo('fast', .5, function() {
+ $(powerTableLevelRows).hide().addClass('InActive');
+ $(powerTableRow).removeClass('InActive').show();
+
+ $(spellBookLevelRows).addClass('InActive');
+ $(spellBookPowerRow).removeClass('InActive').fadeTo('fast', 1);
+ });
+}
+
function notesDirtyCheck() {
var notes_cur = $('#player_notes').val();
if( notes_tmp != notes_cur ) $('#notes_dirty').fadeIn();
@@ -180,19 +206,32 @@ $(window).load(function() {
$('#PowerTable img.power_icon').click(function() {
playerProcessRequest('togglePower', {p_id: this.id.substring(1)}) });
+ // Spellbook Power Activation
+ $('.spellBookRow.InActive').click(function(){ playerProcessRequest('setActivePower', {
+ p_id: this.id.substring(1) }); });
+
// Tab Show/Hide
$('#powerTabLink').click(function() {
$('#PlayerPowers').show();
$('#PlayerSkillsFeats').hide();
+ $('#PlayerSpellbook').hide();
$('#PlayerTabs li.selectedTab').removeClass('selectedTab');
$('#powerTab').addClass('selectedTab');
});
$('#skillTabLink').click(function() {
$('#PlayerPowers').hide();
$('#PlayerSkillsFeats').show();
+ $('#PlayerSpellbook').hide();
$('#PlayerTabs li.selectedTab').removeClass('selectedTab');
$('#skillTab').addClass('selectedTab');
});
+ $('#sbookTabLink').click(function() {
+ $('#PlayerPowers').hide();
+ $('#PlayerSkillsFeats').hide();
+ $('#PlayerSpellbook').show();
+ $('#PlayerTabs li.selectedTab').removeClass('selectedTab');
+ $('#sbookTab').addClass('selectedTab');
+ });
// Power Tooltips
$('img.power_view').each(function(i) {
View
@@ -10,8 +10,23 @@
$power_list = Doctrine_Query::create()
->from('Power p')
->where('p.player_id = ?', $char->id)
- ->orderBy('p.item, p.use_type, p.level, p.name')
+ ->orderBy('p.use_type, p.level, p.name')
->execute();
+
+if( $char->hasSpellbook() ) {
+ $daily_powers = Doctrine_Query::create()
+ ->from('Power p')
+ ->where('p.player_id = ?', $char->id)
+ ->andWhere('p.use_type = ?', Power::POWER_DAILY)
+ ->andWhere('p.power_type = ?', Power::TYPE_ATTACK)
+ ->orderBy('p.level, p.name')
+ ->execute();
+ $utility_powers = Doctrine_Query::create()
+ ->from('Power p')->where('p.player_id = ?', $char->id)
+ ->andWhere('p.power_type = ?', Power::TYPE_UTILITY)
+ ->orderBy('p.level, p.name')
+ ->execute();
+}
?>
<div id="StatBlock">
<div class="statColumn floatColumn">
@@ -154,7 +169,7 @@
<a href="javascript:;" id="skillTabLink">Skills &amp; Feats</a></li>
<? if($char->hasSpellbook()): ?>
<li id="sbookTab">
- <a href="javascript:;" id="sbookTabLink">Spell Book [NYI]</a></li>
+ <a href="javascript:;" id="sbookTabLink">Spell Book</a></li>
<? endif; ?>
</ul>
</div>
@@ -163,11 +178,14 @@
<table id="PowerTable">
<tbody>
<? foreach($power_list as $p): ?>
- <tr id="r<?=$p->id;?>" class="powerRow <?=$p->item?'Item':'';?>
+ <tr id="r<?=$p->id;?>" class="powerRow
+ <?=$p->isActive()?'':'InActive';?>
+ <?=$p->isSpellbookPower()?'l'.$p->level:'';?>
+ <?=Power::TYPE_ITEM==$p->power_type?'Item':'';?>
<?=$p->getUseTypeDisplay(true);?>-bg <?=$p->getUsageStatus();?>">
<td class="icon">
<? if(!$p->isUseType(Power::POWER_ATWILL)): ?>
- <img class="power_icon icon" title="Use/Refresh" id="u<?=$p->id;?>"
+ <img class="power_icon icon" title="Use/Refresh" id="t<?=$p->id;?>"
alt="[*]" src="<?=MEDIA_URL.$p->getUsageIcon();?>" />
<? endif; ?>
</td>
@@ -219,6 +237,54 @@
</table>
</div>
+<? if($char->hasSpellbook()): ?>
+<div id="PlayerSpellbook" class="floatColumn">
+<? if($daily_powers->count() > 0): ?>
+ <table id="SpellbookDailyTable">
+ <tbody>
+ <? $l=0; foreach($daily_powers as $p): ?>
+ <? if($p->level > $l): $l=$p->level; ?>
+ <tr>
+ <th colspan="2">Daily <?=$l;?></th>
+ </tr>
+ <? endif;?>
+ <tr id="b<?=$p->id;?>" class="spellBookRow l<?=$l;?>
+ <?=$p->getUseTypeDisplay(true);?>-bg
+ <?=$p->isActive()?'':'InActive';?>">
+ <td><?=$p->name;?></td>
+ <td class="icon"><img id="d<?=$p->id;?>" class="power_view icon"
+ title="View <?=$p->name;?>" alt="[v]"
+ src="<?=MEDIA_URL;?>/images/icon_magnifying-glass.png"/></td>
+ </tr>
+ <? endforeach; ?>
+ </tbody>
+ </table>
+<? endif;?>
+
+<? if($utility_powers->count() > 0): ?>
+ <table id="SpellbookUtilityTable">
+ <tbody>
+ <? $l=0; foreach($utility_powers as $p): ?>
+ <? if($p->level > $l): $l=$p->level; ?>
+ <tr>
+ <th colspan="2">Utility <?=$l;?></th>
+ </tr>
+ <? endif;?>
+ <tr id="b<?=$p->id;?>" class="spellBookRow l<?=$l;?>
+ <?=$p->getUseTypeDisplay(true);?>-bg
+ <?=$p->isActive()?'':'InActive';?>">
+ <td><?=$p->name;?></td>
+ <td class="icon"><img id="u<?=$p->id;?>" class="power_view icon"
+ title="View <?=$p->name;?>" alt="[v]"
+ src="<?=MEDIA_URL;?>/images/icon_magnifying-glass.png"/></td>
+ </tr>
+ <? endforeach; ?>
+ </tbody>
+ </table>
+<? endif; ?>
+</div>
+<? endif; ?>
+
<div id="PlayerNotes" class="notesColumn">
<div>
<a href="#" id="updateNotes" class="ajaxLink">save notes</a>
View
@@ -161,10 +161,31 @@
'selected="selected"':'';?>><?=$i;?></option>
<? endfor; ?>
</select>&nbsp;&nbsp;
- <label for="item">Magic Item:</label>
- <input type="checkbox" name="item" id="item" value="1"
- <?=$power->getCached('item',$form_key)?
- 'checked="checked"':'';?> />
+ <label for="item"
+ class="<?=$power->hasError('level',$form_key)?'error':'';?>"
+ >Type:</label>
+ <select name="power_type" id="power_type">
+ <option value="<?=Power::TYPE_ATTACK;?>"
+ <?=Power::TYPE_ATTACK==$power->getCached('power_type',$form_key)?
+ 'selected="selected"':'';?>
+ ><?=Power::typeDisplay(Power::TYPE_ATTACK);?></option>
+ <option value="<?=Power::TYPE_UTILITY;?>"
+ <?=Power::TYPE_UTILITY==$power->getCached('power_type',$form_key)?
+ 'selected="selected"':'';?>
+ ><?=Power::typeDisplay(Power::TYPE_UTILITY);?></option>
+ <option value="<?=Power::TYPE_RACIAL;?>"
+ <?=Power::TYPE_RACIAL==$power->getCached('power_type',$form_key)?
+ 'selected="selected"':'';?>
+ ><?=Power::typeDisplay(Power::TYPE_RACIAL);?></option>
+ <option value="<?=Power::TYPE_ITEM;?>"
+ <?=Power::TYPE_ITEM==$power->getCached('power_type',$form_key)?
+ 'selected="selected"':'';?>
+ ><?=Power::typeDisplay(Power::TYPE_ITEM);?></option>
+ <option value="<?=Power::TYPE_OTHER;?>"
+ <?=Power::TYPE_OTHER==$power->getCached('power_type',$form_key)?
+ 'selected="selected"':'';?>
+ ><?=Power::typeDisplay(Power::TYPE_OTHER);?></option>
+ </select>
</div>
</div>
@@ -17,6 +17,8 @@ public function updateFromForm() {
$cache = array();
$cache['error'] = array();
+ if( !$this->exists() ) $this->id = null;
+
// Skill Name
$cache['name'] = $_POST['name'];
if( empty($_POST['name']) ) {
@@ -1003,6 +1003,52 @@ public function subtractMagicItemUse() {
}
}
+ public function activatePower($pID) {
+ global $msg;
+ if( !$this->hasSpellbook() ) {
+ $msg->add('You do not have a spellbook', Message::WARNING);
+ return false;
+ }
+ $power = $this->Powers->get($pID);
+ if( !$power->exists() ) {
+ $msg->add(sprintf("Unable to find power '%s'.", $pID), Message::ERROR);
+ return false;
+ }
+
+ if( Power::TYPE_UTILITY == $power->power_type ) {
+ $power_list = Doctrine_Query::create()
+ ->from('Power p')->where('p.player_id = ?', $this->id)
+ ->andWhere('p.power_type = ?', Power::TYPE_UTILITY)
+ ->andWhere('p.level = ?', $power->level)
+ ->execute();
+ foreach($power_list as $p) {
+ $p->active = ($p->id == $power->id);
+ $p->save();
+ }
+ return array('pID' => $power->id, 'level' => $power->level);
+ }
+ elseif( Power::TYPE_ATTACK == $power->power_type &&
+ Power::POWER_DAILY == $power->use_type ) {
+ $power_list = Doctrine_Query::create()
+ ->from('Power p')->where('p.player_id = ?', $this->id)
+ ->andWhere('p.power_type = ?', Power::TYPE_ATTACK)
+ ->andWhere('p.use_type = ?', Power::POWER_DAILY)
+ ->andWhere('p.level = ?', $power->level)
+ ->execute();
+ foreach($power_list as $p) {
+ $p->active = ($p->id == $power->id);
+ $p->save();
+ }
+ return array('pID' => $power->id, 'level' => $power->level);
+ }
+ else {
+ $msg->add(
+ "Only Utility and Daily Attack spells are part of your spellbook.",
+ Message::ERROR);
+ return false;
+ }
+ }
+
/**
* Returns the attack bonus using a given accessory.
*
Oops, something went wrong.

0 comments on commit 1751c0d

Please sign in to comment.