Skip to content

Commit b026c2b

Browse files
committed
foodlost
2 parents 709fbe8 + 5dcad9b commit b026c2b

File tree

3 files changed

+210
-6
lines changed

3 files changed

+210
-6
lines changed

__init__.py

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# -*- coding: utf-8 -*-
2+
"""The application's model objects"""
3+
4+
from zope.sqlalchemy import ZopeTransactionExtension
5+
from sqlalchemy.orm import scoped_session, sessionmaker,mapper
6+
#from sqlalchemy import MetaData
7+
from sqlalchemy.ext.declarative import declarative_base
8+
from sqlalchemy import Table
9+
import memcache
10+
import time
11+
import json
12+
# Global session manager: DBSession() returns the Thread-local
13+
# session object appropriate for the current web request.
14+
maker = sessionmaker(autoflush=True, autocommit=False,
15+
extension=ZopeTransactionExtension())
16+
DBSession = scoped_session(maker)
17+
mc = memcache.Client(['127.0.0.1:11211'],debug=0)
18+
beginTime=(2011,1,1,0,0,0,0,0,0)
19+
timestr=str(time.strftime('%Y-%m-%d-%H:%M:%S',time.localtime(time.time())))
20+
taskbonus=[]
21+
wartaskbonus=[]
22+
f = file('taskbonus.json')
23+
source = f.read()
24+
target = json.JSONDecoder().decode(source)
25+
f2=file('wartask.json')
26+
source2=f2.read()
27+
if source2!=None:
28+
target2 = json.JSONDecoder().decode(source2)
29+
for t in target:
30+
taskbonus.append([t['id'],t['des'],t['lev']])
31+
for tt in target2:
32+
wartaskbonus.append([tt['id'],tt['des'],tt['lev']])
33+
34+
#newtask = file('newtask.json')
35+
#newtask = newtask.read()
36+
#newtask = json.loads(newtask)
37+
38+
logfile=open("logfile"+timestr,'w')
39+
# Base class for all of our model classes: By default, the data model is
40+
# defined with SQLAlchemy's declarative extension, but if you need more
41+
# control, you can switch to the traditional method.
42+
DeclarativeBase = declarative_base()
43+
44+
# There are two convenient ways for you to spare some typing.
45+
# You can have a query property on all your model classes by doing this:
46+
# DeclarativeBase.query = DBSession.query_property()
47+
# Or you can use a session-aware mapper as it was used in TurboGears 1:
48+
# DeclarativeBase = declarative_base(mapper=DBSession.mapper)
49+
50+
# Global metadata.
51+
# The default metadata is the one from the declarative base.
52+
metadata = DeclarativeBase.metadata
53+
54+
# If you have multiple databases with overlapping table names, you'll need a
55+
# metadata for each database. Feel free to rename 'metadata2'.
56+
#metadata2 = MetaData()
57+
58+
#####
59+
# Generally you will not want to define your table's mappers, and data objects
60+
# here in __init__ but will want to create modules them in the model directory
61+
# and import them at the bottom of this file.
62+
#
63+
######
64+
65+
def init_model(engine):
66+
"""Call me before using any of the tables or classes in the model."""
67+
DBSession.configure(bind=engine)
68+
# If you are using reflection to introspect your database and create
69+
# table objects for you, your tables must be defined and mapped inside
70+
# the init_model function, so that the engine is available if you
71+
# use the model outside tg2, you need to make sure this is called before
72+
# you use the model.
73+
74+
#
75+
# See the following example:
76+
77+
#global t_reflected
78+
79+
#t_reflected = Table("Reflected", metadata,
80+
# autoload=True, autoload_with=engine)
81+
82+
#mapper(Reflected, t_reflected)
83+
global operationaldata_table
84+
global useraccount_table
85+
global businesswrite_table
86+
global businessread_table
87+
global visitfriend_table
88+
operationaldata_table=Table("operationalData",metadata,autoload=True,autoload_with=engine)
89+
businesswrite_table=Table("businessWrite",metadata,autoload=True,autoload_with=engine)
90+
businessread_table=Table("businessRead",metadata,autoload=True,autoload_with=engine)
91+
warmap_table=Table("warMap",metadata,autoload=True,autoload_with=engine)
92+
map_table=Table("map",metadata,autoload=True,autoload_with=engine)
93+
visitfriend_table=Table("visitFriend",metadata,autoload=True,autoload_with=engine)
94+
ally_table=Table("ally",metadata,autoload=True,autoload_with=engine)
95+
victories_table=Table("victories",metadata,autoload=True,autoload_with=engine)
96+
gift_table=Table("gift",metadata,autoload=True,autoload_with=engine)
97+
occupation_table=Table("occupation",metadata,autoload=True,autoload_with=engine)
98+
battle_table=Table("battle",metadata,autoload=True,autoload_with=engine)
99+
news_table=Table("news",metadata,autoload=True,autoload_with=engine)
100+
friend_table=Table("friend",metadata,autoload=True,autoload_with=engine)
101+
friendrequest_table=Table("friendRequest",metadata,autoload=True,autoload_with=engine)
102+
datesurprise_table=Table("datesurprise",metadata,autoload=True,autoload_with=engine)
103+
datevisit_table=Table("datevisit",metadata,autoload=True,autoload_with=engine)
104+
card_table=Table("card",metadata,autoload=True,autoload_with=engine)
105+
caebuy_table=Table("caebuy",metadata,autoload=True,autoload_with=engine)
106+
ppyfriend_table=Table("papayafriend",metadata,autoload=True,autoload_with=engine)
107+
rank_table=Table("rank",metadata,autoload=True,autoload_with=engine)
108+
# useraccount_table=Table("userAccount",metadata,autoload=True,autoload_with=engine)
109+
mapper(warMap,warmap_table)
110+
mapper(operationalData,operationaldata_table)
111+
mapper(businessWrite,businesswrite_table)
112+
mapper(businessRead,businessread_table)
113+
mapper(Map,map_table)
114+
mapper(visitFriend,visitfriend_table)
115+
mapper(Ally,ally_table)
116+
#mapper(userAccount,useraccount_table)
117+
mapper(Victories,victories_table)
118+
mapper(Gift,gift_table)
119+
mapper(Occupation,occupation_table)
120+
mapper(Battle,battle_table)
121+
mapper(News,news_table)
122+
mapper(Friend,friend_table)
123+
mapper(FriendRequest,friendrequest_table)
124+
mapper(Datesurprise,datesurprise_table)
125+
mapper(Datevisit,datevisit_table)
126+
mapper(Card,card_table)
127+
mapper(Caebuy,caebuy_table)
128+
mapper(Papayafriend,ppyfriend_table)
129+
mapper(Rank,rank_table)
130+
# Import your model modules here.
131+
from stchong.model.auth import User, Group, Permission
132+
from stchong.model.operationaldata import operationalData
133+
from stchong.model.businesswrite import businessWrite
134+
from stchong.model.ally import Ally
135+
from stchong.model.victories import Victories
136+
from stchong.model.gift import Gift
137+
from stchong.model.businessread import businessRead
138+
from stchong.model.warmap import warMap
139+
from stchong.model.occupation import Occupation
140+
from stchong.model.visitfriend import visitFriend
141+
from stchong.model.map import Map
142+
from stchong.model.battle import Battle
143+
from stchong.model.news import News
144+
from stchong.model.friend import Friend
145+
from stchong.model.datesurprise import Datesurprise
146+
from stchong.model.datevisit import Datevisit
147+
from stchong.model.friendrequest import FriendRequest
148+
from stchong.model.card import Card
149+
from stchong.model.caebuy import Caebuy
150+
from stchong.model.papayafriend import Papayafriend
151+
from stchong.model.rank import Rank
152+
from stchong.model.dragon import Dragon
153+
from stchong.model.petAtt import PetAtt
154+
from stchong.model.message import Message
155+
#from stchong.model.useraccount import userAccount

clearPet.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import MySQLdb
2+
import json
3+
4+
con = MySQLdb.connect(host='localhost', user='root', db='stcHong', passwd='badperson3')
5+
cursor = con.cursor()
6+
7+
sql = "select pid, friList, lastFeed, state, health from dragon where state >= 2"
8+
cursor.execute(sql)
9+
print sql
10+
allData = cursor.fetchall()
11+
for data in allData:
12+
print str(data)
13+
pid = data[0]
14+
friList = data[1]
15+
lastFeed = data[2]
16+
state = data[3]
17+
health = data[4]
18+
#not update attack
19+
if state > 1: #0 not active 1 buy egg 2 egg
20+
if lastFeed == 0:#not feed
21+
if state == 2:#egg
22+
health -= 1
23+
elif state == 3:#child
24+
health -= 1
25+
elif state == 4:#young
26+
health -= 2
27+
elif state == 5:#old
28+
health -= 10
29+
else:
30+
#if state == 5:
31+
# health -= 10
32+
friList = '[]'
33+
lastFeed = 0
34+
if health < 0 :#no dead at all
35+
#if state == 5:
36+
# state = -1 #dead
37+
# else:
38+
health = 0
39+
sql = "update dragon set health = " + str(health) + ', lastFeed = ' + str(lastFeed)+', friList = \''+str(friList) + '\',trainNum=0 where pid = ' + str(pid)
40+
print sql
41+
cursor.execute(sql)
42+
con.commit()
43+
44+
45+

root.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class RootController(BaseController):
137137
#statuebuilding lev,corn(cae) defenceadd pop time
138138
statuebuilding = [[27,80000,600,20,7200],[30,-8,700,40,14400]]
139139
#decorationbuild:cornorcae,人口上限,解锁等级
140-
decorationbuild=[[10,5,1],[20,5,1],[30,5,1],[50,5,4],[-1,50,5],[100,6,6],[100,6,6],[100,6,6],[100,6,6],[100,6,6],[100,6,6],[200,8,7],[-3,170,8],[400,15,9],[600,20,10],[800,25,11],[1000,30,12],[900,35,13],[1200,40,14],[2000,50,15],[-5,300,10],[1500,60,16],[1500,60,16],[1500,60,16],[1600,65,18],[1600,65,18],[1600,65,18],[1600,65,18],[-3,150,15],[-3,150,15],[-3,150,15],[-3,150,15],[1800,70,20],[1800,70,20],[1800,70,20],[2000,80,25],[2000,80,25],[2000,80,25],[-10,300,20],[5000,90,3],[-5,150,3],[-10,300,3],[2000,30,17],[-10,300,20]]#corn(or cae),populationupbound
140+
decorationbuild=[[10,5,1],[20,5,1],[30,5,1],[50,5,4],[-1,50,5],[100,6,6],[100,6,6],[100,6,6],[100,6,6],[100,6,6],[100,6,6],[200,8,7],[-3,170,8],[400,15,9],[600,20,10],[800,25,11],[1000,30,12],[900,35,13],[1200,40,14],[2000,50,15],[-5,300,10],[1500,60,16],[1500,60,16],[1500,60,16],[1600,65,18],[1600,65,18],[1600,65,18],[1600,65,18],[-3,150,15],[-3,150,15],[-3,150,15],[-3,150,15],[1800,70,20],[1800,70,20],[1800,70,20],[2000,80,25],[2000,80,25],[2000,80,25],[-10,300,20],[5000,90,3],[-5,150,3],[-10,300,3],[2000,30,17],[2000,30,17],[-10,300,20]]#corn(or cae),populationupbound
141141
#农作物list:#corn,exp,food,time,解锁等级
142142
Plant_Price=[[50,1,20,600,1],[165,3,50,2700,1],[-1,8,120,3600,5],[700,7,150,9360,5],[1440,12,300,22680,7],[-3,25,430,14400,7],[230,5,52,1800,13],[600,9,80,5400,16],[-2,30,280,9000,10],[1210,15,200,11520,20],[3000,25,410,29160,25],[-5,50,650,25200,15]]#corn,food,cae
143143
beginTime=(2011,1,1,0,0,0,0,0,0)
@@ -239,7 +239,7 @@ def fetchMsg(self, uid, start, end):
239239
else:
240240
msgs = DBSession.query(Message.mid, Message.uid, Message.mess, Message.time, Message.read, operationalData.otherid).filter_by(fid=uid).filter(Message.uid==operationalData.userid).order_by(desc(Message.time)).slice(start, end).all()
241241
for m in msgs:
242-
print str(m)
242+
#print str(m)
243243
ms = DBSession.query(Message).filter_by(mid=m[0]).one()
244244
ms.read = 1
245245
DBSession.flush()
@@ -4278,6 +4278,8 @@ def warinfo(self,userid):#对外接口,战报
42784278
try:
42794279

42804280
if u.nobility<0:
4281+
u.protecttype = 2
4282+
u.protecttime = t
42814283
mapgrid=newwarmap(u)
42824284
#wartask=wartasknew(u.userid)
42834285
v=DBSession.query(Victories).filter_by(uid=userid).one()
@@ -5892,16 +5894,18 @@ def productall(self,user_id,city_id):
58925894
except InvalidRequestError:
58935895
return dict(id=0)
58945896
@expose('json')
5895-
def getfriendall(self,user_id,user_kind,type):#type=0 normal;type=1 leiji
5897+
def getfriendall(self,user_id,friend_num,type):#type=0 normal;type=1 leiji
5898+
print "getfriend "+str(user_id)
58965899
uid = int(user_id)
58975900
type = int(type)
5901+
friend_num = int(friend_num)
58985902
u = checkopdata(uid)
58995903
cornadd = 0
59005904
flag = 0
59015905
bonus = 0
59025906
k = 0#the number of the friend
59035907
try:
5904-
notvisited = DBSession.query(Papayafriend).filter_by(uid=uid).filter_by(visited=0).all()
5908+
notvisited = DBSession.query(Papayafriend).filter_by(uid=uid).filter_by(visited=0).filter("lev > 0").all()
59055909
if notvisited == None or len(notvisited)==0:
59065910
return dict(id=0, reason="do not have not visited friend")
59075911
card = DBSession.query(Card).filter_by(uid=uid).one()
@@ -5932,9 +5936,8 @@ def getfriendall(self,user_id,user_kind,type):#type=0 normal;type=1 leiji
59325936
temp_cae = temp_cae + 2
59335937
for f in notvisited:
59345938
k += 1
5935-
cornadd += 100 + bonus
59365939
f.visited = 1
5937-
5940+
cornadd = (100 + bonus)*friend_num
59385941
else:
59395942
return dict(id=0, reason="cae or card invalid")
59405943
else:#cae=10
@@ -5947,6 +5950,7 @@ def getfriendall(self,user_id,user_kind,type):#type=0 normal;type=1 leiji
59475950
cornadd += 100 + bonus + 5*k
59485951
k += 1
59495952
f.visited = 1
5953+
cornadd = (100+bonus)*friend_num + 5*(friend_num+1)*friend_num/2
59505954
if flag == 1:
59515955
u.corn = u.corn + cornadd
59525956
u.cae = temp_cae

0 commit comments

Comments
 (0)