# Rest when dead but not lawful, in a map with no karma res point, if not a thiefScenario: UnderworldEnabled True, neutral non-thief corpse goes there if no karma res point
Given I use the "minimal" database
And I set "UnderworldEnabled" in the config file to "True"
And I remove the karma res point for map "0"
And I add player and character "TestBadCorpse04"
And I set the character's alignment to neutral
And I set the character's current HP to "1"
And I put poison berries in the the character's right hand
And the server is started
When I log on as "TestBadCorpse04"
And I enter the game
And I eat "berries"
And within "10" turns I see the message "You are dead"
And I rest
Then I saw a message "The world dissolves around you."
Scenario: UnderworldEnabled False, neutral non-thief corpse doesn't go there if no karma res point
Given I use the "minimal" database
And I set "UnderworldEnabled" in the config file to "False"
And I remove the karma res point for map "0"
And I add player and character "TestBadCorpse04"
And I set the character's alignment to neutral
And I set the character's current HP to "1"
And I put poison berries in the the character's right hand
And the server is started
When I log on as "TestBadCorpse04"
And I enter the game
And I eat "berries"
And within "10" turns I see the message "You are dead"
And I rest
Then I did not see a message "The world dissolves around you."
I took the opportunity to refactor the alignment step a little, so it’s just one step that passes
on the specific alignment as a symbol:
Given(/^I set the character's alignment to (lawful|neutral|evil)$/)do|desired_alignment|set_character_alignment(get_player_id(@user[:char_name]),desired_alignment.to_sym)end
and then I mirror the enum in the server code to push the appropriate value to the DB:
defset_character_alignment(player_id,desired_alignment)alignment_list=[:none,:lawful,:neutral,:chaotic,:evil,:amoral,:all]alignment_num=alignment_list.index(desired_alignment)debug_msg"Alignment #{desired_alignment} is number #{alignment_num}"fail"Unknown alignment"ifalignment_num.nil?client=connect_to_db(@server_database)query="UPDATE [#{@server_database}].[dbo].[Player] SET \
alignment = #{alignment_num} \
WHERE playerID = '#{player_id}'"debug_msgqueryresult=client.execute(query)affected_rows=result.dofail"Unable to update player!"if1!=affected_rowsend
The best way to do it? Not sure; further refactoring will definitely occur as we move toward
testing two separate server implementations.
Given(/^I put a spellbook in the the character's right hand$/)do# TODO - not hardcoded item IDput_attuned_in_player_hand(get_player_id(@user[:char_name]),31000,:right)end
This code only works for databases where the ID for a spellbook happens to be 31000, and gets poor
marks for readability. Let’s add a very flexible item ID lookup method and use that:
Given(/^I put a spellbook in the the character's right hand$/)doitem_id=lookup_item_id({name:'spellbook'})put_attuned_in_player_hand(get_player_id(@user[:char_name]),item_id,:right)end
deflookup_item_id(lookup_hash)client=connect_to_db(@server_database)query=db_field_from_hash('CatalogItem',lookup_hash,'itemID')debug_msg"Query is #{query}"result=client.execute(query)row=result.each(:first=>true)debug_msgrow.inspectfail"Unable to get itemID!"if1!=result.affected_rowsrow[0]['itemID']end
defdb_field_from_hash(table_name,db_hash,return_field)where_clauses=[]db_hash.keys.eachdo|key|ifdb_hash[key].is_a?(String)where_clauses<<"#{key}='#{db_hash[key]}'"elsifdb_hash[key].nil?where_clauses<<"#{key}=NULL"elsewhere_clauses<<"#{key}=#{db_hash[key]}"endendquery="SELECT #{return_field} FROM [dbo].[#{table_name}] "+"WHERE #{where_clauses.join(' AND ')}"end
We’ll probably refactor this further once we have two different data storage mechanisms, but this
will work for now.
Similar code removes a lot of the TODOs, and eventually:
Scenario: Multiple character effects stack correctly
Given I use the "minimal" database
And I add player and character "TestSubject01"
And I inflict fear on the character for "2" turns
And I blind the character for "4" turns
And the server is started
When I log on as "TestSubject01"
And I enter the game
Then I saw a message "You are scared!"
And after "2" turns I no longer see the message "You are scared!"
Then I saw a message "You are blind!"
And after "2" turns I no longer see the message "You are blind!"
Simple, but forced me to learn:
the PlayerEffect slots are one-based, not zero-based (initially my first-applied effect was
ignored).
the display of fear overrides the display of blindess (I’m tempted to call
this a bug).