Skip to content

Commit

Permalink
Current State
Browse files Browse the repository at this point in the history
  • Loading branch information
mharris717 committed Apr 5, 2013
1 parent 031ac25 commit 94a35f5
Show file tree
Hide file tree
Showing 26 changed files with 2,033 additions and 54 deletions.
1 change: 1 addition & 0 deletions .lre
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
load "lib/ascension.rb"
15 changes: 13 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,16 @@ group :development do
end

gem 'mharris_ext'
gem 'rchoice','0.2.0'
#gem 'rchoice', :git => "git@github.com:mharris717/rchoice.git", :branch => "gemdir"
gem "rchoice", :path => '/code/orig/rchoice'
#gem "rchoice", :path => "/users/mharris717/gems/rchoice-0.2.0"
#gem 'rchoice','0.2.0'
#gem 'rchoice', :git => "git@github.com:mharris717/rchoice.git", :branch => "gemdir"

gem "mongo_persist", :path => "/code/orig/mongo_persist"
gem 'andand'

gem 'activesupport'
gem 'bson_ext'
gem 'mongo_scope'
gem 'mongo'
gem 'sinatra'
56 changes: 52 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
PATH
remote: /code/orig/mongo_persist
specs:
mongo_persist (0.0.1)
activesupport
fattr

PATH
remote: /code/orig/rchoice
specs:
rchoice (0.2.0)
andand
mharris_ext

GEM
remote: http://rubygems.org/
specs:
activesupport (3.2.13)
i18n (= 0.6.1)
multi_json (~> 1.0)
andand (1.3.3)
bson (1.7.0)
bson_ext (1.7.0)
bson (~> 1.7.0)
childprocess (0.3.9)
ffi (~> 1.0, >= 1.0.11)
coderay (1.0.9)
diff-lcs (1.1.3)
facets (2.9.3)
fattr (2.2.1)
ffi (1.4.0)
ffi (1.4.0-java)
git (1.2.5)
guard (1.6.2)
listen (>= 0.6.0)
Expand All @@ -22,12 +43,14 @@ GEM
childprocess (>= 0.2.3)
guard (>= 1.1)
spork (>= 0.8.4)
i18n (0.6.1)
jeweler (1.8.4)
bundler (~> 1.0)
git (>= 1.2.5)
rake
rdoc
json (1.7.7)
json (1.7.7-java)
listen (0.7.3)
lre (0.3.0)
fattr
Expand All @@ -38,14 +61,24 @@ GEM
mharris_ext (1.6.0)
facets
fattr
mongo (1.7.0)
bson (~> 1.7.0)
mongo_scope (0.0.5)
mongo
multi_json (1.7.1)
pry (0.9.12)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.4)
pry (0.9.12-java)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.4)
spoon (~> 0.0)
rack (1.5.2)
rack-protection (1.5.0)
rack
rake (10.0.4)
rchoice (0.2.0)
andand
mharris_ext
rdoc (3.12.2)
json (~> 1.4)
rr (1.0.4)
Expand All @@ -57,24 +90,39 @@ GEM
rspec-expectations (2.8.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.8.0)
sinatra (1.3.6)
rack (~> 1.4)
rack-protection (~> 1.3)
tilt (~> 1.3, >= 1.3.3)
slop (3.4.3)
spoon (0.0.3)
ffi
spork (0.9.2)
terminal-table (1.4.5)
thor (0.17.0)
tilt (1.3.6)
watchr (0.7)

PLATFORMS
java
ruby

DEPENDENCIES
activesupport
andand
bson_ext
bundler (>= 1.0.0)
guard
guard-rspec
guard-spork
jeweler (~> 1.8.4)
lre
mharris_ext
rchoice (= 0.2.0)
mongo
mongo_persist!
mongo_scope
rchoice!
rdoc (~> 3.12)
rr
rspec (~> 2.8.0)
sinatra
26 changes: 26 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,29 @@ Rake::RDocTask.new do |rdoc|
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end

task :environment do
load "lib/ascension.rb"
end

task :dump_game => :environment do
require 'json'
obj = Game.collection.find.to_a[0]
str = obj.to_json
File.create "vol/game.json",str

require 'pp'

File.open("vol/game_pp.json","w") do |f|
PP.pp(obj,f)
end
end

task :reset_game => :environment do
Game.collection.remove
Game.reset!
puts Game.collection.find_one_object.mongo_id
end



115 changes: 113 additions & 2 deletions lib/ascension.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
require 'mharris_ext'
require 'rchoice'
require 'mongo_persist'

def playing_on_command_line?
$playing_on_command_line = true if $playing_on_command_line.nil?
$playing_on_command_line
end

%w(to_json).each do |f|
load File.dirname(__FILE__) + "/ascension/#{f}.rb"
end

def db
Mongo::Connection.new.db('ascension')
end

class Array
def sum
Expand All @@ -20,23 +34,110 @@ def fire(event)
end

class Game
setup_mongo_persist :sides, :center, :void, :honor, :deck, :turn_manager
def addl_json_attributes
%w(mongo_id engageable_cards constant_cards current_side_index last_update_dt)
end

fattr(:sides) { [] }
fattr(:center) { Center.new(:game => self) }
fattr(:void) { Void.new }
fattr(:honor) { 60 }
fattr(:deck) { CenterDeck.starting }
fattr(:center_wc) { CenterWithConstants.new(:game => self) }
fattr(:turn_manager) { TurnManager.new(:game => self) }

def engageable_cards
turn_manager.current_side.engageable_cards
end
def constant_cards
center_wc.constant_cards
end
def current_side_index
turn_manager.current_side_index
end
def last_update_dt
Time.now
end

def card_places
places = [deck,center,void]
sides.each do |side|
places += [side.hand,side.discard,side.deck,side.played]
end
places
end

def after_mongo_load
center.game = self
turn_manager.game = self

sides.each do |s|
s.game = self
%w(discard deck hand played constructs).each do |m|
s.send(m).side = s
end
s.choices.each do |c|
c.side = s
end
end

card_places.each do |cards|
cards.hydrate!
end
end

def find_card(card_id)
raise "blank card id" if card_id.blank?
card_places.each do |cards|
res = cards.find { |x| x.card_id.to_s == card_id.to_s }
return res if res
end
raise "no card #{card_id}"
end

class << self
def reset!
Game.collection.remove
game = Game.new
side = Side.new(:game => game)
game.sides << side
game.sides << Side.new(:game => game)

game.deck = CenterDeck.starting
#game.deck << Parse.get("Mephit")
game.center.fill!
#side.deck << game.deck.get_one('Temple Librarian')
#side.deck[-1] = Card::Hero.arha

#side.deck << Parse.get("Shade ot Black Watch")
#side.deck << Parse.get("Seer of the Forked Path")
#side.deck << Parse.get("Demon Slayer")
game.sides.each do |s|
s.draw_hand!
end
#side.hand << game.deck.get_one('Void Thirster')
#side.deck << game.deck.get_one('Void Initiate')

game.mongo.save!
game
end
end
end

class Side
include FromHash
setup_mongo_persist :discard, :deck, :hand, :played, :constructs, :honor, :side_id, :choices
attr_accessor :game
fattr(:discard) { Discard.new(:side => self) }
fattr(:deck) { PlayerDeck.starting(:side => self) }
fattr(:hand) { Hand.new(:side => self) }
fattr(:played) { Played.new(:side => self) }
fattr(:constructs) { Constructs.new(:side => self) }
fattr(:honor) { 0 }
fattr(:side_id) { rand(100000000000000) }
fattr(:choices) { [] }

def draw_hand!
5.times { draw_one! }
end
Expand Down Expand Up @@ -66,6 +167,16 @@ def defeat(monster)
monster.apply_abilities(self)
played.pool.power -= monster.power_cost
end
def engage(card)
if card.monster?
defeat(card)
else
purchase(card)
end
end
def engageable_cards
game.center_wc.engageable_cards(self)
end
def end_turn!
played.discard!
hand.discard!
Expand Down Expand Up @@ -93,6 +204,6 @@ def print_status!
end
end

%w(card cards ability pool events parse).each do |f|
require File.dirname(__FILE__) + "/ascension/#{f}"
%w(card cards ability pool events parse turn_manager setup_rchoice).each do |f|
load File.dirname(__FILE__) + "/ascension/#{f}.rb"
end
Loading

0 comments on commit 94a35f5

Please sign in to comment.