Skip to content

Commit

Permalink
Tests for fight, map, skills,
Browse files Browse the repository at this point in the history
add egg item, modifications to try to improve npcs, especially that
tricksy thief.
  • Loading branch information
tchalvak committed Oct 7, 2023
1 parent e8727a3 commit c96f5a0
Show file tree
Hide file tree
Showing 16 changed files with 190 additions and 28 deletions.
35 changes: 35 additions & 0 deletions cypress/e2e/fight.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* eslint-disable semi */
/// <reference types="cypress" />
// eslint-disable-next-line no-unused-vars
/* global cy Cypress describe beforeEach afterEach it */

// getting started guide:
// https://on.cypress.io/introduction-to-cypress

describe('fight', () => {
beforeEach(() => {
cy.standardLogin()
})
afterEach(() => {
})

it('displays someone to fight', () => {
cy.visit('/enemies')
cy.contains('Fight')
cy.url().should('match', /enemies$/u)
cy.get('[role=heading]').contains('Fight').should('be.visible')
cy.contains('Attack').should('be.visible')
cy.get('.avatar').should('be.visible')
})

// NPC checks
it('can attack a thief', () => {
cy.visit('/enemies')
cy.url().should('match', /enemies$/u)
cy.get('[role=heading]').contains('Fight').should('be.visible')
cy.contains('Attack a').should('be.visible')
cy.get('a[href*="/npc/attack/thief"]').first().click()
cy.contains('sees you and prepares to defend!').should('be.visible')
// Hmm, will fail on random group of thieves
})
});
38 changes: 38 additions & 0 deletions cypress/e2e/map.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint-disable semi */
/// <reference types="cypress" />
// eslint-disable-next-line no-unused-vars
/* global cy Cypress describe beforeEach afterEach it */

// getting started guide:
// https://on.cypress.io/introduction-to-cypress

describe('check map loads', () => {
beforeEach(() => {
cy.standardLogin()
})
afterEach(() => {
})

it('displays map doshin', () => {
cy.visit('/map')
cy.contains('Map')
cy.url().should('match', /map$/u)
cy.get('[role=heading]').should('be.visible')
cy.contains('Map').should('be.visible')
cy.contains('Doshin').should('be.visible')
cy.contains('Shrine').should('be.visible')
cy.contains('Village Square').should('be.visible')
})

// it('displays the map even for logged out users', () => {
// cy.logout()
// cy.visit('/map')
// cy.contains('Map')
// cy.url().should('match', /map$/u)
// cy.get('[role=heading]').should('be.visible')
// cy.contains('Map').should('be.visible')
// cy.contains('Doshin').should('be.visible')
// cy.contains('Shrine').should('be.visible')
// cy.contains('Village Square').should('be.visible')
// })
});
2 changes: 1 addition & 1 deletion cypress/e2e/signup.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('signup a new ninja', () => {
cy.get('input[type=email]').type(`ninjawarstchalvak+cypress-testing${random}@gmail.com`)
cy.get('input[type=password]').first().type(Cypress.env('TEST_PASSWORD'), { log: false })
cy.get('input[type=password][name=cpass]').type(Cypress.env('TEST_PASSWORD'), { log: false })
cy.get('input[name=send_name]').type(`cypress-test-user${random}`)
cy.get('input[name=send_name]').type(`Viper-${random}`)
cy.get('input[type=submit]').click()
cy.get('[role=alert]').should('not.exist')
cy.contains('You are almost ready to be a ninja!').should('be.visible')
Expand Down
24 changes: 24 additions & 0 deletions cypress/e2e/skills.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-disable semi */
/// <reference types="cypress" />
// eslint-disable-next-line no-unused-vars
/* global cy Cypress describe beforeEach afterEach it */

// getting started guide:
// https://on.cypress.io/introduction-to-cypress

describe('check skills for current ninja', () => {
beforeEach(() => {
cy.standardLogin()
})
afterEach(() => {
})

it('displays skills', () => {
cy.visit('/skill')
cy.contains('Skills')
cy.url().should('match', /skill$/u)
cy.get('[role=heading]').contains('Skills').should('be.visible')
cy.contains('Dueling Combat Skills').should('be.visible')
cy.contains('Passive Skills').should('be.visible')
})
});
9 changes: 9 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ Cypress.Commands.add('standardLogin', () => {
)
})

Cypress.Commands.add('logout', () => {
cy.visit('/logout')
// wait for the url to not be logout
cy.log('After logout it should redirect');
cy.url().should('include', 'loggedout', { timeout: 10000 })
cy.log('Cypress logout() command ran')
cy.log('========= Logout should now be COMPLETE --RR =======')
})

// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
Expand Down
17 changes: 12 additions & 5 deletions deploy/lib/control/NpcController.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ private function attackAbstractNpc(string $victim, Player $player, array $npcs):
$reward_item = (isset($npc_stats['item']) && $npc_stats['item'] ? $npc_stats['item'] : null);
$is_quick = (bool) ($npco->getSpeed() > $player->getSpeed()); // Beyond basic speed and they see you coming, so show that message.
$is_weaker = ($npco->getStrength() * 3) < $player->getStrength(); // Npc much weaker?
$is_stronger = ($npco->getStrength()) > ($player->getStrength() * 3); // Npc More than twice as strong?
$enemy_strength = $npco->getStrength();
$much_stronger = ($npco->getStrength()) > ($player->getStrength() * 3); // Npc much stronger?
$image = $npc_stats['img'] ?? $npc_stats['full_img'] ?? null;
// Assume defeat...
$victory = false;
Expand All @@ -185,9 +186,10 @@ private function attackAbstractNpc(string $victim, Player $player, array $npcs):
$npc_damage = $npco->damage();
$ninja_damage = $player->damage();
$npc_damage_class = Combat::determineDamageClass($npc_damage, $player->health);
$ninja_damage_class = Combat::determineDamageClass($ninja_damage, $npco->getHealth());
$npc_health = $npco->getHealth();
$ninja_damage_class = Combat::determineDamageClass($ninja_damage, $npc_health);
$survive_fight = $player->harm($npc_damage);
$kill_npc = ($npco->getHealth() <= $ninja_damage);
$kill_npc = ($npc_health <= $ninja_damage);

if ($survive_fight > 0) {
// The ninja survived, they get any gold the npc has.
Expand All @@ -200,8 +202,9 @@ private function attackAbstractNpc(string $victim, Player $player, array $npcs):
// Victory occurred, reward the poor sap.
if ($npco->inventory()) {
$inventory = new Inventory($player);
$npc_inventory = array_keys($npco->inventory());

foreach (array_keys($npco->inventory()) as $l_item) {
foreach ($npc_inventory as $l_item) {
$item = Item::findByIdentity($l_item);
$received_items[] = $item->getName();
$inventory->add($item->identity(), 1);
Expand Down Expand Up @@ -244,7 +247,9 @@ private function attackAbstractNpc(string $victim, Player $player, array $npcs):
'victory' => $victory,
'survive_fight' => $survive_fight,
'ninja_damage' => $ninja_damage,
'npc_damage' => $npc_damage,
'npc_damage_class' => $npc_damage_class,
'npc_health' => $npc_health,
'ninja_damage_class' => $ninja_damage_class,
'kill_npc' => $kill_npc,
'image_path' => $image_path,
Expand All @@ -255,7 +260,9 @@ private function attackAbstractNpc(string $victim, Player $player, array $npcs):
'is_villager' => $npco->hasTrait('villager'),
'race' => $npco->race(),
'is_weaker' => $is_weaker,
'is_stronger' => $is_stronger,
'much_stronger' => $much_stronger,
'enemy_strength' => $enemy_strength,
'tagline' => $npco->tagline(),
]
];
}
Expand Down
11 changes: 11 additions & 0 deletions deploy/lib/data/Npc.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Npc implements Character
public $race;
public $gold;
public $bounty_mod;
public $tagline;

public function __construct($content)
{
Expand Down Expand Up @@ -284,4 +285,14 @@ public function minGold()
{
return (int) ($this->hasTrait('rich') ? floor($this->gold()/self::RICH_MIN_GOLD_DIVISOR) : self::MIN_GOLD);
}

/**
* Any tagline they get
*
* @return string
*/
public function tagline()
{
return $this->tagline;
}
}
1 change: 1 addition & 0 deletions deploy/lib/data/NpcFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public static function fleshOutFromData($data, $npc)
$npc->gold = @$data['gold'];
$npc->traits_array = (isset($data['traits']) && is_array($data['traits']) ? $data['traits'] : []);
$npc->inventory = null; // The actual instance inventory is intitially just null;
$npc->tagline = @$data['tagline'];
}

/**
Expand Down
18 changes: 14 additions & 4 deletions deploy/npc-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

use NinjaWars\core\data\NpcFactory;

/**
* Note that 1+stamina*5 is health, plus 2*stamina if armored.
*/

// Npc matrix planning document: https://docs.google.com/spreadsheet/ccc?key=0AkoUgtBBP00HdGZ1eUhaekhTb1dnZVh3ZlpoRExWdGc#gid=0
NpcFactory::$data = [
'firefly' => [ // Baseline weakest mob
Expand Down Expand Up @@ -131,13 +135,14 @@
],
'thief2' => [
'name' => 'Thief',
'strength' => 17,
'strength' => 16,
'stamina' => 10,
'speed' => 10,
'speed' => 11,
'race' => 'human',
'img' => 'thief.png',
'inventory' => [
'shuriken' => '0.9',
'shuriken' => '.9',
'shell' => '1',

],
'gold' => 40,
Expand All @@ -147,6 +152,7 @@
'gang',
'defender',
],
'tagline' => 'Beware the Ninja Thieves, they have entered this world to steal from all!',
],
'peasant2' => [
'name' => 'Peasant',
Expand All @@ -172,7 +178,7 @@
'name' => 'Merchant',
'race' => 'human',
'strength' => 10,
'stamina' => 20,
'stamina' => 15,
'speed' => 10,
'ki' => 1,
'damage' => 15,
Expand Down Expand Up @@ -268,6 +274,9 @@
'escaper',
'flying',
],
'inventory' => [
'egg' => '.3',
],
],
] + (
!defined('DEBUG') || !DEBUG ? [] :
Expand All @@ -277,6 +286,7 @@
'short' => 'swarms and buzzes through the air',
'strength' => 13,
'speed' => 30,
'stamina' => 4,
'damage' => 6,
'gold' => 0,
'race' => 'insect',
Expand Down
19 changes: 19 additions & 0 deletions deploy/sql/migrations/2023-10-06-add-some-items.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
insert into item (
item_internal_name,
item_display_name,
item_cost,
image,
for_sale,
usage, ignore_stealth, covert, turn_cost, target_damage,
turn_change, self_use, plural, other_usable, traits
)
values
(
'egg',
'Egg',
1,
'',
default,
'The egg of some creature', default, default, default, default,
default, default, 's', default, 'food'
);
2 changes: 1 addition & 1 deletion deploy/templates/fight.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1>Fight</h1>
<h1 role='heading'>Fight</h1>
<link rel="stylesheet" type="text/css" href="{cachebust file="/css/enemies.css"}" media="Screen" />
<script src='{cachebust file="/js/fightConfig.js"}'></script>

Expand Down
4 changes: 2 additions & 2 deletions deploy/templates/map.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1>Map</h1>
<h1 role='heading'>Map</h1>

<div id='attack-player-page'>

Expand Down Expand Up @@ -30,4 +30,4 @@
</script>
{/if}

</div><!-- End of attack-player page container div -->
</div><!-- End of attack-player page container div -->
15 changes: 10 additions & 5 deletions deploy/templates/npc.abstract.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ article#fight nav{
{if $is_quick or $npco->hasTrait('defender')}
The {$race|escape} sees you and prepares to defend!
{/if}
{if $is_stronger}
{if $much_stronger}
The {$race|escape} seems stronger than you!
{/if}

Expand Down Expand Up @@ -116,18 +116,23 @@ article#fight nav{
{if $is_weaker}
<p class='ninja-notice target-escape'>The {$display_name|escape} flees from you and escapes!</p>
{else}
{if $is_stronger}
<p class='you-escape'>You are unable to kill the {$display_name|escape}, so you escape instead!</p>
{if $much_stronger}
<p class='you-escape' title='They had {$enemy_strength|escape} strength'>You are unable to end the {$display_name|escape}, so you escape instead!</p>
{else}
<p>You fight to a standstill and neither wins.</p>
<p title='They had {$npc_health} health'>You fight to a standstill and neither wins.</p>
{/if}
{/if}
{if $tagline}
<p><em>{$tagline}</em></p>
{/if}

{/if}

<section id='rewards'>
{if $received_gold}<p>You gather <span class='gold'>{$received_gold} gold</span>.</p>{/if}
{foreach from=$received_display_items item=display_item}<p>You obtained <span class='obtained-item'>{$display_item}</span>!</p>{/foreach}
{foreach from=$received_display_items item=display_item}
<p>You obtained <span class='obtained-item'>{$display_item}</span>!</p>
{/foreach}
&nbsp;
</section>

Expand Down
10 changes: 5 additions & 5 deletions deploy/templates/npc.list.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
<h3>Attack a:</h3>
<div id='npc-list' class='centered'>
{foreach name="person" from=$npcs key="idx" item="npc"}
<div class='creature person'>
<nav class='creature person'>
<a href='/npc/attack/{$npc.identity|escape}' target='main' class='m-box'><img alt='' src='images/characters/{$npc.image|escape:'url'|escape}'> {$npc.name|escape}</a>
</div>
</nav>
{/foreach}
{foreach name="creatures" from=$other_npcs key="idx" item="npc"}
<div class='creature'>
<nav class='creature'>
<a href='/npc/attack/{$idx|escape}' target='main' class='m-box'>
{if isset($npc.img) && $npc.img}
<img alt='' class='creature-image' src='images/characters/{$npc.img|escape:'url'|escape}'>
{else}
<i class="fa fa-asterisk" aria-hidden="true"></i>
{/if}
{$npc.name|escape}</a>
</div>
</nav>
{/foreach}
</div>
</section>
</section>
Loading

0 comments on commit c96f5a0

Please sign in to comment.